Creating Mail message with attachments

how-to

(Mark Alldritt) #1

Here is a snippet of code showing how to create an email message with an attachment using the Mail application.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

property emailSubject : "Your Email Subject"
property emailSender : "Your Name <your_address@domain.com>"
property recipientName : "Someone"
property recipientEmail : "someone@domain.com"
property messageBody : "Hello,

This is a test message generated by AppleScript.

"

set attachmentFile to choose file

tell application "Mail"
	set default message format to plain format
	tell (make new outgoing message with properties {subject:emailSubject, content:messageBody, sender:emailSender})
		make new to recipient at end of to recipients with properties {name:recipientName, address:recipientEmail}
		make new attachment with properties {file name:attachmentFile} at after the last character
		
		--	Uncomment to actually send the message
		--send
	end tell
end tell

(Mark Alldritt) #2

2 posts were split to a new topic: Exporting Mail mailboxes