AnsweredAssumed Answered

Email multiple email attachments using Applescript

Question asked by steveoh on Jan 29, 2016
Latest reply on Aug 14, 2017 by TimAcri

Hi again!


So I'm trying to create a javascript to send multiple attachments (maximum of 7 attachments) using javascript.  I've done some investigations and have found some posted similar discussions, but when attempting the same on my solution I end up with 'Object not found' and "Unknown Error - 1728" errors.


Basically I have the attachments exported to the desktop as simply a number (i.e. 1.pdf, 2.pdf, ... 7.pdf).  These are added with a loop to zTemp on separate lines with a full desktop path with "file:../" & $counter (which works fine).


The issue lies somewhere in my applescript, which I pieced together from other similar discussions, my Applescript is:


-- tell application "FileMaker Pro Advanced"

       set theSubject to cell "_Core::Template_Subject" of current table

       set theMessage to cell "_Core::Template_Body" of current table

       set theRecipient to cell "_Core::Template_Recipients" of current record

       set theAttachments to cell "_Core::zTemp" of current record

       -- return-separated Mac:file paths

-- end tell


set attachmentList to {}

repeat with i in paragraphs of theAttachments

       set theAttachment to i

       set aliasAttachment to theAttachment as alias

       set attachmentList to attachmentList & aliasAttachment

end repeat


set theMessage to theMessage & return & return

     -- otherwise it jams it up against the text


tell application "Mail"


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

       tell newMessage

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

       tell content

       repeat with i in attachmentList

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

       end repeat

  end tell


  save newMessage

       -- send newMessage

       -- switch the commenting on the above 2 lines to send immediately

  end tell

end tell


Any help would be really appreciated!  I've labored over this for a while and need a fresh perspective!  Worth noting is that I'm a novice with applescript, in case my posting of it here wasn't ample evidence of that.