我知道在Linux/MacOS中有方法从终端发送电子邮件,但我似乎找不到关于如何做到这一点的适当文档。

基本上,我需要它为我的bash脚本,通知我每次有一个文件的变化。


当前回答

我认为斯威克斯是最好的。这里有一个更复杂的例子,在端口25上使用TLS加密:

swaks --from john.smith@mydomain.com \
--h-From: '"John Smith" <john.smith@mydomain.com>' \
--h-Subject: 'Subject of message' \
--auth LOGIN --auth-user mylogin --auth-pass mypass \
--to someone@otherdomain.com \
--server smtp.example.com --port 25 -tls \
--add-header 'Content-Type: text/plain; charset="utf-8"'

其他回答

进入终端,输入man mail寻求帮助。

你需要设置SMTP:

http://hints.macworld.com/article.php?story=20081217161612647

参见:

http://www.mactricksandtips.com/2008/09/send-mail-over-your-network.html

Eg:

mail -s "hello" "example@example.com" <<EOF
hello
world
EOF

这将发送一封电子邮件到example@example.com,主题为hello和消息

你好 世界

我认为斯威克斯是最好的。这里有一个更复杂的例子,在端口25上使用TLS加密:

swaks --from john.smith@mydomain.com \
--h-From: '"John Smith" <john.smith@mydomain.com>' \
--h-Subject: 'Subject of message' \
--auth LOGIN --auth-user mylogin --auth-pass mypass \
--to someone@otherdomain.com \
--server smtp.example.com --port 25 -tls \
--add-header 'Content-Type: text/plain; charset="utf-8"'
echo "this is the body" | mail -s "this is the subject" "to@address"

如果您想在Linux上附加一个文件

echo 'mail content' | mailx -s 'email subject' -a attachment.txt username@stackoverflow.com

如果你只需要一个主题行(就像在一个警告消息中一样),简单地做:

mailx -s "This is all she wrote" < /dev/null "myself@myaddress"