Merge pull request #14286 from Modrisco/master

Finish translating
This commit is contained in:
Xingyu.Wang 2019-06-23 20:30:45 +08:00 committed by GitHub
commit 2b8a7f45b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 168 additions and 171 deletions

View File

@ -1,171 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (Modrisco)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to send email from the Linux command line)
[#]: via: (https://www.networkworld.com/article/3402027/how-to-send-email-from-the-linux-command-line.html)
[#]: author: (Sandra Henry-Stocker https://www.networkworld.com/author/Sandra-Henry_Stocker/)
How to send email from the Linux command line
======
Linux offers several commands that allow you to send email from the command line. Here's look at some that offer interesting options.
![Molnia/iStock][1]
There are several ways to send email from the Linux command line. Some are very simple and others more complicated, but offer some very useful features. The choice depends on what you want to do - whether you want to get a quick message off to a co-worker or send a more complicated message with an attachment to a large group of people. Here's a look at some of the options:
### mail
The easiest way to send a simple message from the Linux command line is to use the **mail** command. Maybe you need to remind your boss that you're leaving a little early that day. You could use a command like this one:
```
$ echo "Reminder: Leaving at 4 PM today" | mail -s "early departure" myboss
```
**[ Two-Minute Linux Tips:[Learn how to master a host of Linux commands in these 2-minute video tutorials][2] ]**
Another option is to grab your message text from a file that contains the content you want to send:
```
$ mail -s "Reminder:Leaving early" myboss < reason4leaving
```
In both cases, the -s options allows you to provide a subject line for your message.
### sendmail
Using **sendmail** , you can send a quick message (with no subject) using a command like this (replacing "recip" with your intended recipient:
```
$ echo "leaving now" | sendmail recip
```
You can send just a subject line (with no message content) with a command like this:
```
$ echo "Subject: leaving now" | sendmail recip
```
You can also use sendmail on the command line to send a message complete with a subject line. However, when using this approach, you would add your subject line to the file you intend to send as in this example file:
```
Subject: Requested lyrics
I would just like to say that, in my opinion, longer hair and other flamboyant
affectations of appearance are nothing more ...
```
Then you would send the file like this (where the lyrics file contains your subject line and text):
```
$ sendmail recip < lyrics
```
Sendmail can be quite verbose in its output. If you're desperately curious and want to see the interchange between the sending and receiving systems, add the -v (verbose) option:
```
$ sendmail -v recip@emailsite.com < lyrics
```
### mutt
An especially nice tool for command line emailing is the **mutt** command, though you will likely have to install it first. Mutt has a convenient advantage in that it can allow you to include attachments.
To use mutt to send a quick messsage:
```
$ echo "Please check last night's backups" | mutt -s "backup check" recip
```
To get content from a file:
```
$ mutt -s "Agenda" recip < agenda
```
To add an attachment with mutt, use the -a option. You can even add more than one as shown in this command:
```
$ mutt -s "Agenda" recip -a agenda -a speakers < msg
```
In the command above, the "msg" file includes content for the email. If you don't have any additional content to provide, you can do this instead:
```
$ echo "" | mutt -s "Agenda" recip -a agenda -a speakers
```
The other useful option that you have with mutt is that it provides a way to send carbon copies (using the -c option) and blind carbon copies (using the -b option).
```
$ mutt -s "Minutes from last meeting" recip@somesite.com -c myboss < mins
```
### telnet
If you want to get deep into the details of sending email, you can use **telnet** to carry on the email exchange operation, but you'll need to, as they say, "learn the lingo." Mail servers expect a sequence of commands that include things like introducing yourself ( **EHLO** command), providing the email sender ( **MAIL FROM** command), specifying the email recipient ( **RCPT TO** command), and then adding the message ( **DATA** ) and ending the message with a "." as the only character on the line. Not every email server will respond to these requests. This approach is generally used only for troubleshooting.
```
$ telnet emailsite.org 25
Trying 192.168.0.12...
Connected to emailsite.
Escape character is '^]'.
220 localhost ESMTP Sendmail 8.15.2/8.15.2/Debian-12; Wed, 12 Jun 2019 16:32:13 -0400; (No UCE/UBE) logging access from: mysite(OK)-mysite [192.168.0.12]
EHLO mysite.org <== introduce yourself
250-localhost Hello mysite [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-EXPN
250-VERB
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5
250-DELIVERBY
250 HELP
MAIL FROM: me@mysite.org <== specify sender
250 2.1.0 shs@mysite.org... Sender ok
RCPT TO: recip <== specify recipient
250 2.1.5 recip... Recipient ok
DATA <== start message
354 Enter mail, end with "." on a line by itself
This is a test message. Please deliver it for me.
. <== end message
250 2.0.0 x5CKWDds029287 Message accepted for delivery
quit <== end exchange
```
### Sending email to multiple recipients
If you want to send email from the Linux command line to a large group of recipients, you can always use a loop to make the job easier as in this example using mutt.
```
$ for recip in `cat recips`
do
mutt -s "Minutes from May meeting" $recip < May_minutes
done
```
### Wrap-up
There are quite a few ways to send email from the Linux command line. Some tools provide quite a few options.
Join the Network World communities on [Facebook][3] and [LinkedIn][4] to comment on topics that are top of mind.
--------------------------------------------------------------------------------
via: https://www.networkworld.com/article/3402027/how-to-send-email-from-the-linux-command-line.html
作者:[Sandra Henry-Stocker][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/Modrisco)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.networkworld.com/author/Sandra-Henry_Stocker/
[b]: https://github.com/lujun9972
[1]: https://images.idgesg.net/images/article/2017/08/email_image_blue-100732096-large.jpg
[2]: https://www.youtube.com/playlist?list=PL7D2RMSmRO9J8OTpjFECi8DJiTQdd4hua
[3]: https://www.facebook.com/NetworkWorld/
[4]: https://www.linkedin.com/company/network-world

View File

@ -0,0 +1,168 @@
[#]: collector: (lujun9972)
[#]: translator: (Modrisco)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (How to send email from the Linux command line)
[#]: via: (https://www.networkworld.com/article/3402027/how-to-send-email-from-the-linux-command-line.html)
[#]: author: (Sandra Henry-Stocker https://www.networkworld.com/author/Sandra-Henry_Stocker/)
如何用 Linux 命令行发电子邮件
======
Linux 提供了几种命令允许您通过终端发送电子邮件,下面来展示一些有趣的方法。
![Molnia/iStock][1]
Linux 可以用多种方式通过命令行发送电子邮件。有一些方法十分简单,有一些相对会复杂一些,不过仍旧提供了很多有用的特性。选择哪一种方式取决于你想要什么 —— 向同事快速发送消息,还是向一批人群发带有附件的更复杂的信息。接下来看一看几种可行方案:
### mail
发送一条简单消息最便捷的 Linux 命令是 `mail`。假设你需要提醒老板你今天得早点走,你可以使用这样的一条命令:
```
$ echo "Reminder: Leaving at 4 PM today" | mail -s "early departure" myboss
```
另一种方式是从一个文件中提取出你想要发送的文本信息:
```
$ mail -s "Reminder:Leaving early" myboss < reason4leaving
```
在以上两种情况中,你都可以通过 -s 来为邮件添加标题。
### sendmail
使用 `sendmail` 命令可以发送一封不包含标题的快信。(用目标收件人替换 `recip`
```
$ echo "leaving now" | sendmail recip
```
你可以用这条命令发送一条只有标题,没有内容的信息:
```
$ echo "Subject: leaving now" | sendmail recip
```
你也可以用 `sendmail` 发送一条包含一条标题行的完整信息。不过使用这个方法时,你的标题行会被添加到要发送的文件中,如下例所示:
```
Subject: Requested lyrics
I would just like to say that, in my opinion, longer hair and other flamboyant
affectations of appearance are nothing more ...
```
你也可以发送这样的文件lyric 文件包含标题和正文):
```
$ sendmail recip < lyrics
```
`sendmain` 的输出可能会很冗长。如果你感到好奇并希望查看发送系统和接收系统之间的交互,请添加 `-v` verbose选项。
```
$ sendmail -v recip@emailsite.com < lyrics
```
### mutt
`mutt` 是通过命令行发送邮件的一个很好的工具,在使用前你需要安装它。 `mutt` 的一个很方便的优势就是它允许你在邮件中添加附件。
使用 `mutt` 发送一条快速信息:
```
$ echo "Please check last night's backups" | mutt -s "backup check" recip
```
从文件中获取内容:
```
$ mutt -s "Agenda" recip < agenda
```
使用 `-a` 选项在 `mutt` 中添加附件。你甚至可以添加不止一个附件 —— 如下一条命令所示:
```
$ mutt -s "Agenda" recip -a agenda -a speakers < msg
```
在以上的命令中,`msg` 文件包含了邮件中的正文。如果你没有其他补充的内容,你可以这样来代替之前的命令:
```
$ echo "" | mutt -s "Agenda" recip -a agenda -a speakers
```
`mutt` 另一个有用的功能是可以添加抄送(`-c`)和密送(`-b`)。
```
$ mutt -s "Minutes from last meeting" recip@somesite.com -c myboss < mins
```
### telnet
如果你想深入了解发送电子邮件的细节,你可以使用 `telnet` 来进行电子邮件交互操作。但正如所说的那样,你需要“学习术语”。邮件服务器期望一系列命令,其中包括自我介绍(`EHLO` 命令)、提供发件人(`MAIL FROM` 命令)、指定收件人(`RCPT TO` 命令),然后添加消息(`DATA`)并以 `.` 结束消息。并不是所有的电子邮件服务器都会响应这些请求。此方法通常仅用于故障排除。
```
$ telnet emailsite.org 25
Trying 192.168.0.12...
Connected to emailsite.
Escape character is '^]'.
220 localhost ESMTP Sendmail 8.15.2/8.15.2/Debian-12; Wed, 12 Jun 2019 16:32:13 -0400; (No UCE/UBE) logging access from: mysite(OK)-mysite [192.168.0.12]
EHLO mysite.org <== introduce yourself
250-localhost Hello mysite [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-EXPN
250-VERB
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5
250-DELIVERBY
250 HELP
MAIL FROM: me@mysite.org <== specify sender
250 2.1.0 shs@mysite.org... Sender ok
RCPT TO: recip <== specify recipient
250 2.1.5 recip... Recipient ok
DATA <== start message
354 Enter mail, end with "." on a line by itself
This is a test message. Please deliver it for me.
. <== end message
250 2.0.0 x5CKWDds029287 Message accepted for delivery
quit <== end exchange
```
### 向多个收件人发送电子邮件
如果你希望通过 Linux 命令行向一大组收件人发送电子邮件,你可以使用一个循环来帮助你完成任务,如下面应用在 `mutt` 中的例子:
```
$ for recip in `cat recips`
do
mutt -s "Minutes from May meeting" $recip < May_minutes
done
```
### 总结
有很多方法可以从 Linux 命令行发送电子邮件。有些工具提供了相当多的选项。
--------------------------------------------------------------------------------
via: https://www.networkworld.com/article/3402027/how-to-send-email-from-the-linux-command-line.html
作者:[Sandra Henry-Stocker][a]
选题:[lujun9972][b]
译者:[Modrisco](https://github.com/Modrisco)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.networkworld.com/author/Sandra-Henry_Stocker/
[b]: https://github.com/lujun9972
[1]: https://images.idgesg.net/images/article/2017/08/email_image_blue-100732096-large.jpg
[2]: https://www.youtube.com/playlist?list=PL7D2RMSmRO9J8OTpjFECi8DJiTQdd4hua
[3]: https://www.facebook.com/NetworkWorld/
[4]: https://www.linkedin.com/company/network-world