How to send email from Terminal?

2019-01-05 08:07发布

I know there are ways to send email from terminal in Linux/MacOS, but I can't seem to find proper documentation on how to do that.

Basically I need it for my bash script that notifies me every time there is a change in a file.

5条回答
smile是对你的礼貌
2楼-- · 2019-01-05 08:13

If all you need is a subject line (as in an alert message) simply do:

mailx -s "This is all she wrote" < /dev/null "myself@myaddress"
查看更多
一夜七次
3楼-- · 2019-01-05 08:18

in the terminal on your mac os or linux os type this code

mail -s (subject) (receiversEmailAddress)  <<< "how are you?"

for an example try this

mail -s "hi" abc@example.com <<< "how are you?"<br>
查看更多
成全新的幸福
4楼-- · 2019-01-05 08:21

If you want to attach a file on Linux

echo 'mail content' | mailx -s 'email subject' -a attachment.txt username@stackoverflow.com
查看更多
爷、活的狠高调
5楼-- · 2019-01-05 08:26

Go into Terminal and type man mail for help.

You will need to set SMTP up:

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

See also:

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

Eg:

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

This will send an email to example@example.com with the subject hello and the message

Hello

World

查看更多
ゆ 、 Hurt°
6楼-- · 2019-01-05 08:29
echo "this is the body" | mail -s "this is the subject" "to@address"
查看更多
登录 后发表回答