Jump to content
Server Maintenance This Week. ×

How to attach multiple files to a Mail message


This topic is 4790 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Has anyone used AppleScript to attach multiple images to an outgoing mail message?

I'm exporting multiple images to the user's temp folder in FileMaker 9, so I know the paths. I can create the message with the first file attached using the Send Mail script step.

I thought for once I'd ask if anyone has done this before I attempt it on my own. I know basic AppleScript, but it never seems to work quite the way I expect it to. I'm pretty sure it can do this.

(I'm open to non-AS ideas too.)

Link to comment
Share on other sites

  • 2 months later...

You probably have a solution for this by now.

If not, here is an example using the Finder and MS Entourage:

tell application "Finder"

set attchList to every file of alias "Mac HD:Users:UserName:Desktop:TestDATA:"

set theCNT to count of attchList

if theCNT = 1 then

set attchList to attchList as alias as list

else

set attchList to every file of alias "Mac HD:Users:UserName:Desktop:TestDATA:" as alias list

end if

end tell

tell application "Microsoft Entourage"

set newEvent to make new outgoing message at end of folder id 2 with properties {subject:"New Pictures", attachment:attchList, to recipients:"[email protected]"}

send newEvent

end tell

Link to comment
Share on other sites

Here is much the same for FileMaker and Apple Mail. Included is a FileMaker file; the attached file paths are Mac paths in a FileMaker field, return-separated.

It first tests each path to see if the file is really there.

-- Basic create/send email with attachments via Apple Mail

tell application "FileMaker Pro Advanced"

  tell current record

    set theSubject to cell "Subject"

    set theMessage to cell "Message" & return & return

    set theRecipient to cell "Recipient"

    set att_txt to cell "Attachments"

    -- return-separated Mac:file paths

    set atts_txt to paragraphs of att_txt

    -- text to AppleScript list

    set theSender to cell "Sender"

  end tell

end tell

-- test for each attachment file; add to list as alias

set theAttachments to {}

try

  repeat with i in atts_txt

    set theAttachments to theAttachments & alias i

  end repeat

on error

  beep

  display alert "Error with Attachments" message "Could not find attachment file:" & return & (i as text) buttons {"Cancel"} default button 1

  return

end try

tell application "Mail"

  launch

  set newMessage to make new outgoing message with properties {subject:theSubject, content:theMessage}

  tell newMessage

    if theSender is not "" then

      set sender to theSender

      -- optional; otherwise uses default email account

    end if

    make new to recipient at end of to recipients with properties {address:theRecipient}

    repeat with i in theAttachments

      make new attachment with properties {file name:i} at after the last paragraph

    end repeat

    

    save newMessage

    --send newMessage

    -- remove the commenting on the line above to send immediately

  end tell

end tell

Mail_wAttach_simple.zip

Link to comment
Share on other sites

P.S. In the FileMaker file, the above AppleScript is in a Perform AppleScript step, in the "Email wAttachments wError" script. But it has this line uncommented:

send newMessage

So it will send the email immediately.

Also, the file paths of the attachments are obviously on my computer, so you'll need to put your own.

It would be possible to add a scripted mechanism to "choose file" (or "choose folder") to add file paths (references) to that field.

Link to comment
Share on other sites

  • 2 months later...

I did finally come up with my own solution - kind of forgot about this topic.

Fenton's solution suits me a little better since it doesn't use the "every file" construct. This means I can save attachments to the user's temp folder, which may contain other files that should not be attachments.

Thanks very much to both of you.

Link to comment
Share on other sites

  • 1 year later...

While declarations like this is pretty healthy, would almost every scripting including embedded applescripts be of a hybrid nature:

ell application "FileMaker Pro Advanced"

tell current record

set theSubject to cell "Subject"

set theMessage to cell "Message" & return & return

set theRecipient to cell "Recipient"

set att_txt to cell "Attachments"

-- return-separated Mac:file paths

set atts_txt to paragraphs of att_txt

-- text to AppleScript list

set theSender to cell "Sender"

end tell

end tell

I would suggest a tiny hack using a bit of both more of the native scripting to fill in the missing bits - if you just after the filemaker native Send Mail put this tiny calculated embedded AS:


"tell application "Mail"¶

	set theMessage to last outgoing message¶

	tell theMessage¶

		set visible to true¶

		make new to recipient at beginning of to recipients with properties {address:""

& Untitled::reciever & 

""}¶

	send¶

	end tell¶

end tell"

Here is it the reciever the applescript property being added, but it goes the same way with attachments, it does in my humble opinion minimize the need for a substantial declaration part.

--sd

I attach a tiny template showing this, but please change the receiver address in the first line of the script, to your own!!!!!

hybridscripting.zip

Edited by Guest
Link to comment
Share on other sites

  • 3 months later...

Anyone know how I would add two attachments to an email?

Specifically, I need to add two attachments, both referenced as variables, to an email.

I have a student database which loops through each record, attaching their individual grade card to an email and sends the email. This works great, except now I need to add a second attachment to each email. And each attachment is specific to the user.

Thanks,

Scott

Link to comment
Share on other sites

  • 1 year later...

hi Søren

I like the concept of your solution. Do you ( or anyone) know how to modify it to add multiple attachments (as the option in the send script doesn't allow more than one.)

While declarations like this is pretty healthy, would almost every scripting including embedded applescripts be of a hybrid nature:

I would suggest a tiny hack using a bit of both more of the native scripting to fill in the missing bits - if you just after the filemaker native Send Mail put this tiny calculated embedded AS:


"tell application "Mail"¶

	set theMessage to last outgoing message¶

	tell theMessage¶

		set visible to true¶

		make new to recipient at beginning of to recipients with properties {address:""

& Untitled::reciever & 

""}¶

	send¶

	end tell¶

end tell"

Here is it the reciever the applescript property being added, but it goes the same way with attachments, it does in my humble opinion minimize the need for a substantial declaration part.

--sd

I attach a tiny template showing this, but please change the receiver address in the first line of the script, to your own!!!!!

Link to comment
Share on other sites

You probably know of this already and may have a reason for using Apple script but a good alternative would be the SMTP-it plug in, plain text, rich text and html emails, with as many attachments as you like, I have been using it for years, works well.

Vincent

Link to comment
Share on other sites

You probably know of this already and may have a reason for using Apple script but a good alternative would be the SMTP-it plug in, plain text, rich text and html emails, with as many attachments as you like, I have been using it for years, works well.

Vincent

I dont have the plug in and prefer to stear away as they complicate things as all the staff then need it.

Link to comment
Share on other sites

This topic is 4790 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.