Tuesday, October 1, 2013

Send Mail with multiple attachments to multiple recipients through AppleScript !



#Read file for mail body
set filePath to "/Users/......../MailBodyText.txt"
set theContent to (read filePath)

                 OR

#Compose mail body
set theContent to "Hi,

New build is available. Please find the details below:
Version: 1.1.1
URL:http://...........ipa

Detailed release note is attached for your reference.

Regards,
Dev-Team
"

#set file for attachment
set theAttachment1 to POSIX file "/Users/............/release_notes.xls"

#set Another attachment for latest log file
set attachFilePath to "/Users/....../builds/" & LatestFolderName & "/log"
set theAttachment2 to POSIX file attachFilePath


#Set Recipients
set nameList to {"Archana Chaurasia", "Recipient2", "Recipient3"}
set addressList to {"archana.2207@gmail.com", "Recipient2@test.com", "Recipient3@test.com"}

#Mail Tell Block
tell application "Mail"
           #Create the message
           set theMessage to make new outgoing message with properties {subject:releaseVersioncontent:theContentvisible:true}
           #Set a recipient
           tell theMessage
              make new attachment with properties {file name:theAttachment1at after the last paragraph
              make new attachment with properties {file name:theAttachment2at after the last paragraph
              repeat with i from 1 to count nameList
                        make new to recipient at end of to recipients with properties {name:item i of nameListaddress:item i of addressList}
              end repeat
#Send the Message
            send
            end tell

end tell

3 comments: