Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to create a "Mail Service" with Mac Automator to create a New Message that automagically fills the body with the content of ascii file ~/Documents/MailBody.txt

I can select the file with "Find Finder Items", but not sure how to get its content to pass it as input to "New Mail Message". Note I want to add the content of the file to the body, not to attach the file itself.

Thanks a lot in advance.

share|improve this question
Is the content of the MailBody.txt HTML or plain text? – elhombre Nov 19 '11 at 20:18
it is plaint text – user1055640 Nov 19 '11 at 20:49
I reply myself, I found a solution. The first action in the workflow is "Run Shell Script" which just 'cat ~/Documents/MailBody.txt'. This actions returns "text", which is passed as input to action "New Mail Message". – user1055640 Nov 20 '11 at 17:34
Well then reply with the "Post your answer" button. Just for your information, you will not be able to input multiple lines of text into the mail form with this solution – elhombre Nov 21 '11 at 1:06

The solution I have found is this: the first action in the workflow is "Run Shell Script" which just cat ~/Documents/MailBody.txt. This actions returns "text", which is passed as input to action "New Mail Message". It seems to work fine, even when the txt file has multiple lines.

share|improve this answer

Using the shell is a pretty cool solution.

Just in case you wanted a more "Automator-esque" solution, you could try the following sequence:

1) Get Specified Finder Items (point it at your txt file)

2) Open Finder Items (select so it will open in TextEdit)

3) Get Contents of TextEdit Document (this returns the text you need for the rest of the workflow)

share|improve this answer
I have just tried that way and it didn't work. Also, it actually opens TextEdit app, which is kind of annoying. – user1055640 Nov 26 '11 at 18:06

I created a Automator Service that receives Files or folder from

The first action is to Get Selected Finder Items. It then passes these files to a Run AppleScript action containing the following:

on run {input, parameters}

    set thisFilePath to (the first item of the input) as text
    set fileContents to do shell script "cat " & quoted form of POSIX path of thisFilePath

    tell application "Mail"
        set composeMessage to (a reference to (make new outgoing message))
        tell composeMessage
            set the content to fileContents
            set visible to true
        end tell
    end tell

end run

This grabs the file name of the first file selected, which is then passed to a shell script that uses cat to get the contents of the text file. Then AppleScript is used to create a new message with the contents of the file as the body of the message.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.