我知道在Linux/MacOS中有方法从终端发送电子邮件,但我似乎找不到关于如何做到这一点的适当文档。
基本上,我需要它为我的bash脚本,通知我每次有一个文件的变化。
我知道在Linux/MacOS中有方法从终端发送电子邮件,但我似乎找不到关于如何做到这一点的适当文档。
基本上,我需要它为我的bash脚本,通知我每次有一个文件的变化。
当前回答
在MAC操作系统或Linux操作系统的终端上输入这段代码
mail -s (subject) (receiversEmailAddress) <<< "how are you?"
举个例子
mail -s "hi" abc@example.com <<< "how are you?"<br>
其他回答
在MAC操作系统或Linux操作系统的终端上输入这段代码
mail -s (subject) (receiversEmailAddress) <<< "how are you?"
举个例子
mail -s "hi" abc@example.com <<< "how are you?"<br>
如果你只需要一个主题行(就像在一个警告消息中一样),简单地做:
mailx -s "This is all she wrote" < /dev/null "myself@myaddress"
我认为斯威克斯是最好的。这里有一个更复杂的例子,在端口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"'
可能最简单的方法是使用curl,不需要安装任何额外的包,它可以直接在请求中配置。
以下是使用gmail smtp服务器的示例:
curl --url 'smtps://smtp.gmail.com:465' --ssl-reqd \
--mail-from 'from-email@gmail.com' \
--mail-rcpt 'to-email@gmail.com' \
--user 'from-email@gmail.com:YourPassword' \
-T <(echo -e 'From: from-email@gmail.com\nTo: to-email@gmail.com\nSubject: Curl Test\n\nHello')
echo "this is the body" | mail -s "this is the subject" "to@address"