Ich versuche, mit Hilfe von Bash und Applescript E-Mails vom Terminal zu senden. Ich verwende Bash, um mich um Argumente und den Text der E-Mail-Nachricht zu kümmern. Dann habe ich versucht, mit Applescript die Mail mit Mail.app zu versenden. Ich bin jedoch auf einige Probleme gestoßen, wenn ich Folgendes versuche, bekomme ich: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}
Aktualisierte 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
Vielleicht möchten Sie sich auch diesen SuperUser-Beitrag ansehen . Die akzeptierte Antwort stellt ein Bash-Skript bereit, das AppleScript verwendet, um eine E-Mail mit einem Anhang von einer Terminal-Befehlszeile aus zu senden. Dieses Skript bietet möglicherweise mehr Funktionen, als Sie benötigen, aber es ist ein guter Ausgangspunkt. Der Code aus der Antwort:
#!/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
Müssen Sie Mail.app verwenden oder möchten Sie nur eine E-Mail-Nachricht senden? Wenn Sie nur eine E-Mail-Nachricht vom Terminal aus senden möchten, können Sie das Befehlszeilendienstprogramm sendemail verwenden.
/usr/local/bin/sendemail
-f from@my.email.com
-t my.recipient@their.email.com
-s your.smtp.server:port
-xu smtp.username.here
-xp smtp.password.here
-m message.body.goes.here
Offensichtlich muss das alles in Terminal in einer einzigen Zeile stehen, mit entsprechenden Escapezeichen und String-Zitaten. Weitere Optionen finden Sie auf der Manpage für sendemail.
foo