Articles/Articles/Mac Integration

AppleScript Support

Postbox Support
posted this on March 28, 2011 03:09 PM

Postbox provides Apple Script support for sending messages from applications such as iCal, iPhoto and Alfred.app.

You can take advantage of the Postbox AppleScript dictionary in your own applications such as FileMaker Pro to send messages through Postbox too!

Example Apple Script

-- open a compose window populated with the the following parameters:
-- aRecipient e-mail address of the recipient
-- aSubject the message subject (optional)
-- aMessageBodyText the text to appear in the compose body (optional)
-- aAttachmentPath file path to the attachment to be included (optional)
-- aCcRecipients a list of cc recipients (optional)
-- aBccRecipients a list of bcc recipients (optional)
on send_mail(aRecipientAddress, aSubject, aMessageBodyText, aAttachmentPath, aCcRecipients, aBccRecipients)
	tell application "Postbox"
		send message subject aSubject recipient aRecipientAddress cc recipients aCcRecipients bcc recipients bccRecipients body aMessageBodyText attachment aAttachmentPath with args
		activate
	end tell
end send_mail

-- Send in the background with out opening a compose window with the following parameters:
-- aRecipient e-mail address of the recipient
-- aSubject the message subject (optional)
-- aMessageBodyText the text to appear in the compose body (optional)
-- aAttachmentPath file path to the attachment to be included (optional)
on send_mail_in_background(aRecipientAddress, aSubject, aMessageBodyText, aAttachmentPath)
	tell application "Postbox"
		send message subject aSubject recipient aRecipientAddress body aMessageBodyText attachment aAttachmentPath with in background and args
		activate
	end tell
end send_mail_in_background

-- open a compose window populated with the the following parameters
-- aRecipients an applescript list of e-mail addresses to send to
-- aSubject the message subject (optional)
-- aMessageBodyText the text to appear in the compose body (optional)
-- aAttachmentPath file path to the attachment to be included (optional)
on send_mail_to_recipients(aRecipients, aSubject, aMessageBodyText, aAttachmentPath)
	tell application "Postbox"
		send message subject aSubject recipients aRecipients body aMessageBodyText attachment aAttachmentPath with args
		activate
	end tell
end send_mail_to_recipients

Example Calls

Here are several examples of how to call these helper methods

send_mail("stoakron@postbox-inc.com", "", "", "")

send_mail("Scott MacGregor ", "", "", "")

send_mail("Sto Akron <stoakron@postbox-inc.com>, Sherman Dickman <thisisatest@postbox-inc.com>", "This is a Subject", "This is a message Body.", "~/Desktop/test.txt", ["john
doe ", "peter paul "], ["Steve
Smith "])

send_mail_in_background("stoakron@postbox-inc.com", "This is a Subject", "This is a message Body\nwith line returns\n", "~/Desktop/test.txt")

send_mail_in_background("stoakron@postbox-inc.com", "This is a Subject", "This is a message Body.", "~/Desktop/test.txt:~/Desktop/test2.txt")

Additional Notes

  • To insert line returns in the message body parameter, you may need to use \n for each line return.
  • To insert multiple attachments, separate them by a ':' such as "~/Desktop/test.txt:~/Desktop/test2.txt"
 
Topic is closed for comments