How do I Send Email from the Command Line?

2019-04-19 06:37发布

I would like to quickly send email from the command line. I realize there are probably a number of different ways to do this.

I'm looking for a simple way to do this from a linux terminal (likely a bash shell but anything should do) and an alternative way to do this on Windows. I want to be able to whip up an email right on the command line or have the flexibility to pipe the message into the command line program. How would you go about doing this? If you have small scripts that would be fine as well.

8条回答
爷的心禁止访问
2楼-- · 2019-04-19 07:26

You can use mail:

$mail -s <subject> <recipients>

You then type your message and end it with a line that has only a period. This signals you are done and sends the message.

You can also pipe your email in from STDIN and it will be sent as the text of an email:

$<mail-generating-program> | mail -s <subject> <recipients>

One small note with this approach - unless your computer is connected to the internet and your DNS settings are set properly, you won't be able to receive replies to your message. For a more robust command-line program you can link to your POP or IMAP email account, check out either pine or mutt.

查看更多
聊天终结者
3楼-- · 2019-04-19 07:27
$ echo "This is the email body" | mail -s "This is the subject" me@email.com

Alternatively:

$ cat | mail -s "A few lines off the top of my head" me@here.com
This is where my
multiline
message would go
^D

^D - means press ctrl+d

查看更多
登录 后发表回答