My Reply to E-mail with Text File AppleScript

At work I deal with a large volume of e-mail. There just aren’t enough people to handle all the e-mail requests or questions. When I have people to help handle e-mail, I still answer some of the same questions over and over and over. You just don’t want to know the volume or scope of my daily e-mail chores.

As a long time MacOS user I have repeatedly turned to AppleScript as a useful tool for dealing with making the same e-mail replies constantly (the real solution is to fix the breakdown in communication, but that’s a whole other story). Here is the most recent incarnation of my AppleScript solution using Apple Mail on MacOS 10.6.

My solution is simple; Highlight the message, run the script, select a pre-written text file to include, customize the reply, and send. The respondent gets a solution or reply that is usually edited over time for clarity, and I get to customize it a bit so it doesn’t seem too much like an auto-reply.

tell application "Mail"

set theSelection to selection
set theSelectedMessage to item 1 of theSelection
set theSelectedMessageSender to sender of theSelectedMessage

set theSelectedMessageSenderName to extract name from sender of theSelectedMessage
set theSelectedMessageSenderAddress to extract address from sender of theSelectedMessage

set theSelectedMessageSubject to subject of theSelectedMessage
set theSelectedMessageContent to content of theSelectedMessage

set myHomeDefault to the path to home folder
set myHomeDefault to myHomeDefault & "nicholls:Documents:e-mail_templates:" as text
set myHomeDefault to myHomeDefault as alias

set myTemplateFile to (choose file with prompt "Select E-mail Template File:" of type {"TEXT"} default location myHomeDefault)

open for access myTemplateFile
set prefsContents to read myTemplateFile using delimiter {"#–#"}
close access myTemplateFile
set MessageText to item 1 of prefsContents

set theMessage to make new outgoing message with properties {visible:true, subject:"Re: " & theSelectedMessageSubject, content:MessageText & theSelectedMessageContent}
tell theMessage
make new to recipient at end of to recipients with properties {name:theSelectedMessageSenderName, address:theSelectedMessageSenderAddress}
make new bcc recipient at end of bcc recipients with properties {name:"Website Manager", address:""}
end tell
end tell

This is a sample text file I might use. I made this really basic. You should note the #–# deliminator used. I have that so I can do some other interesting things with the templates, like BCC: my boss if I have too. Anyway this would be saved something like email-reply-standard.txt and I would load it through the dialog created by the script when it runs.

Thank you for your interest!

If you have further questions, please let me know.

Jess Planck

Nice Signature with phone
Probably has the website too

—-[ Your Original Message Follows ]—-


For some reason the syntaxhighligher I’ve got here doesn’t like AppleScript comments, so I’ve removed them.

One response to “My Reply to E-mail with Text File AppleScript”

  1. Hi Jess,

    I am completely new with AppleScript, but I really need to automate some answers in Mail. However, Automator does not have a “Reply to” for Mail (only for Outlook) so I understood I’d need to use AppleScript.

    Is there any chance you’d explain this to me with a lot of details?
    (For example > how do I first create and save my e-mail templates, etc).
    Detailing each step would be really helpful !

    Thanks in advance for your help,


Leave a Reply

Your email address will not be published. Required fields are marked *