I'm trying to send mail from terminal with the help of bash and applescript. I use bash for taking care of arguments and the email message body. Then I have tried using Applescript to send the mail with Mail.app. I have run into some problems though, when I try the following I get: 4:4: syntax error: Expected expression but found end of script. (-2741)
#!/bin/bash if [ $# -ne 2 ] then echo "Arguments: <subject> <recipient>" >&2 #stderr exit 1 fi read message applescript=" tell application \"Mail\" set theMessage to make new outgoing message with properties {visible:true, subject:${1}, content:${message}, address:${2}} send theMessage end tell " # send the message osascript -e ${applescript} Updated version:
#!/bin/bash if [ $# -ne 2 ] then echo "Arguments: <subject> <recipient>" >&2 #stderr exit 1 fi read message echo "tell application \"Mail\" set theEmail to make new outgoing message with properties {visible:true, subject:\"${1}\", content:\"${message}\"} tell theEmail make new recipient at end of to recipients with properties {address:\"${2}\"} send theEmail end tell end tell" | osascript