bash 如何从终端发送电子邮件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8260858/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 21:14:23  来源:igfitidea点击:

How to send email from Terminal?

bashemailterminal

提问by NoobDev4iPhone

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.

我知道有多种方法可以在 Linux/MacOS 中从终端发送电子邮件,但我似乎找不到有关如何执行此操作的正确文档。

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

基本上,我的 bash 脚本需要它,每次文件发生更改时都会通知我。

采纳答案by gadgetmo

Go into Terminal and type man mailfor help.

进入终端并输入man mail帮助。

You will need to set SMTPup:

您将需要设置SMTP

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

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

See also:

也可以看看:

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

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

Eg:

例如:

mail -s "hello" "[email protected]" <<EOF
hello
world
EOF

This will send an email to [email protected]with the subject helloand the message

这将发送一封[email protected]包含主题hello和消息的电子邮件

Hello

World

你好

世界

回答by earldouglas

echo "this is the body" | mail -s "this is the subject" "to@address"

回答by JRFerguson

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"

回答by Aliaksandr Sushkevich

Probably the simplest way is to use curlfor this, there is no need to install any additional packages and it can be configured directly in a request.

可能最简单的方法是使用curl它,不需要安装任何额外的包,它可以直接在请求中配置。

Here is an example using gmail smtp server:

以下是使用 gmail smtp 服务器的示例:

curl --url 'smtps://smtp.gmail.com:465' --ssl-reqd \
  --mail-from '[email protected]' \
  --mail-rcpt '[email protected]' \
  --user '[email protected]:YourPassword' \
  -T <(echo -e 'From: [email protected]\nTo: [email protected]\nSubject: Curl Test\n\nHello')

回答by MiaeKim

If you want to attach a file on Linux

如果要在 Linux 上附加文件

echo 'mail content' | mailx -s 'email subject' -a attachment.txt [email protected]

回答by Pramodya Abeysinghe

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

在 mac os 或 linux os 上的终端中键入此代码

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

for an example try this

例如试试这个

mail -s "hi" [email protected] <<< "how are you?"<br>

回答by Tum

For SMTP hosts and Gmail I like to use Swaks -> https://easyengine.io/tutorials/mail/swaks-smtp-test-tool/

对于 SMTP 主机和 Gmail,我喜欢使用 Swaks -> https://easyengine.io/tutorials/mail/swaks-smtp-test-tool/

On a Mac:

在 Mac 上:

  1. brew install swaks
  2. swaks --to [email protected] --server smtp.example.com
  1. brew install swaks
  2. swaks --to [email protected] --server smtp.example.com