Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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 start writing an email with Mail.app from Terminal, and add an attachment. Something like this:

macbook:~ me$ /Applications/Mail.app/Contents/MacOS/Mail -s the_subject -to email@domain.com < ~/Downloads/file.zip
share|improve this question
up vote 3 down vote accepted

You can do this using AppleScript. Here's a quick (quickly tested) bash script which is close to what you want.

#!/bin/bash
echo "tell application \"Mail\"
    activate

    set MyEmail to make new outgoing message with properties {visible:true, subject:\"$2\", content:\"Some Message Here\"}
    tell MyEmail
        make new to recipient at end of to recipients with properties {address:\"$1\"}
        make new attachment with properties {file name:((\"$3\" as POSIX file) as alias)}
    end tell
end tell
" | osascript

Usage: compose_email 'email@domain.com' 'Some Subject' /path/to/attachment.zip

share|improve this answer
    
Script needs a few tweaks... stay tuned! – Josh Mar 31 '10 at 2:34
    
Script tested and working – Josh Mar 31 '10 at 2:49
    
Thanks, thats exactly what i was looking for. – DerKlops Mar 31 '10 at 7:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .