linux命令行发送串口_从命令行在Linux中发送电子邮件

linux命令行发送串口

In this article, you will learn how to send emails using the popular mail commands. It’s equally important that you also learn how to send Linux email attachments.

在本文中,您将学习如何使用常用的邮件命令发送电子邮件。 同样重要的是,您还学习了如何发送Linux电子邮件附件。

Some of the command line options used are:

使用的一些命令行选项是:

  • -s: denotes the mail’s subject

    -s :表示邮件的主题
  • -a: for denoting attachment

    -a :表示附件
  • -c: for the copy email address (CC)

    -c :用于复制电子邮件地址(CC)
  • -b: for the blind copy email address (BCC)

    -b :用于密件副本电子邮件地址(BCC)

Linux从命令行发送电子邮件 (Linux Send Email from Command Line)

We will learn about following commands to send emails in Linux.

我们将学习以下命令以在Linux中发送电子邮件。

  1. mail

    邮件
  2. mailx

    邮件
  3. mutt

    杂种
  4. mpack

    压缩包
  5. sendmail

    发送邮件

1.使用邮件命令 (1. Using mail Command)

Linux mail command is quite popular and is commonly used to send emails from the command line. Mail is installed as part of mailutils and mailx packages on Debian and Redhat systems respectively. The two commands process messages on the command line.

Linux邮件命令非常流行,通常用于从命令行发送电子邮件。 邮件分别作为Debian和Redhat系统上mailutilsmailx软件包的一部分安装。 这两个命令在命令行上处理消息。

To install mailutils in Debian and Ubuntu Systems, run:

要在Debian和Ubuntu系统中安装mailutils,请运行:

$ sudo apt install mailutils -y

For CentOS and RedHat distributions, run:

对于CentOS和RedHat发行版,运行:

$ yum install mailx

When you run the command, the following window will pop up. Press the TAB button and hit on ‘OK’

运行命令时,将弹出以下窗口。 按下TAB按钮并点击“确定”

In the next Window, scroll and hit ‘Internet Site’.

在下一个窗口中,滚动并单击“ Internet站点”。

The system will thereafter finish up with the installation process.

此后,系统将完成安装过程。

测试邮件命令 (Testing Mail command)

If the mail command is successfully installed, test the application by using the following format and press enter:

如果已成功安装mail命令,请使用以下格式测试应用程序,然后按Enter:

$ mail –s "Test Email" email_address

Replace email_address with your email address.

用您的电子邮件地址替换email_address

For example,

例如,

$ mail –s "Test Email" james@example.com

After pressing “Enter”, you’ll be prompted for a Carbon Copy (Cc:) address. If you wish not to include a copied address, proceed and hit ENTER.

按“ Enter”后,将提示您输入复本(Cc :)地址。 如果您不希望包含复制的地址,请继续并按ENTER键。

Next, type the message or the body of the Email and hit ENTER.

接下来,键入消息或电子邮件正文,然后按Enter。

Finally, Press Ctrl + D simultaneously to send the Email.

最后,同时按Ctrl + D键发送电子邮件。

Output

输出量

Alternatively, you can use the echo command to pipe the message you want to send to the mail command as shown below.

或者,您可以使用echo命令将要发送的消息通过管道传递到mail命令,如下所示。

$ echo "sample message" | mail -s "sample mail subject" email_address

For example,

例如,

$ echo "Hello world" | mail -s "Test" james@example.com

Output

输出量

Let’s assume you have a file that you want to attach. Let’s call the file message.txt
How do you go about it? Use the command below.

假设您有一个要附加的文件。 我们将其称为message.txt文件
你如何去做? 使用下面的命令。

$ mail -s "subject" -A message.txt email_address

The -A flag defines attachment of the file.

-A标志定义文件的附件。

For example;

例如;

$ mail -s "Important Notice" -A message.txt james@example.com

Output

输出量

To send an email to many recipients run:

要将电子邮件发送给许多收件人,请运行:

$ mail –s "test header" email_address email_address2

2.使用mailx命令 (2. Using the mailx command)

Mailx is the newer version of mail command and was formerly referred to as nail in other implementations. Mailx has been around since 1986 and was incorporated into POSIX in the year 1992.

Mailx是mail命令的更新版本,在其他实现中以前被称为nail 。 Mailx自1986年以来一直存在,并于1992年并入POSIX。

Mailx is part of the Debian’s mail compound package used for various scenarios. Users, system administrators, and developers can use this mail utility. The implementation of mailx also takes the same form as the mail command line syntax.

Mailx是Debian邮件复合软件包的一部分,用于各种情况。 用户,系统管理员和开发人员可以使用此邮件实用程序。 mailx的实现也采用与邮件命令行语法相同的形式。

To install mailx in Debian/Ubuntu Systems run:

要在Debian / Ubuntu Systems中安装mailx,请运行:

$ sudo apt install mailx

To install mailx in RedHat & CentOS run:

要在RedHat和CentOS中安装mailx,请运行:

$ yum install mailx

测试Mailx命令 (Testing Mailx command)

You may use the echo command to direct the output to the mail command without being prompted for CC and the message body as shown here:

您可以使用echo命令将输出定向到mail命令,而无需提示输入CC和消息正文,如下所示:

$ echo "message body" | mail -s "subject" email_address

For example,

例如,

$ echo "Make the most out of Linux!" | mail -s "Welcome to Linux" james@example.com

3.使用MUTT命令 (3. Using the MUTT Command)

Mutt is a lightweight Linux command line email client. Unlike the mail command that can do basic stuff, mutt can send file attachments. Mutt also reads emails from POP/IMAP servers and connecting local users via the terminal.

Mutt是一个轻量级的Linux命令行电子邮件客户端。 与可以执行基本任务的mail命令不同,mutt可以发送文件附件。 Mutt还从POP / IMAP服务器读取电子邮件,并通过终端连接本地用户。

To install mutt in Debian / Ubuntu Systems run:

要在Debian / Ubuntu系统中安装mutt,请运行:

$ sudo apt install mutt

To install mutt in Redhat / CentOS Systems run:

要在Redhat / CentOS系统中安装mutt,请运行:

$ sudo yum install mutt

测试Mutt命令 (Testing Mutt command)

You can send a blank message usign mutt with the < /dev/null right after the email address.

您可以在电子邮件地址后的< /dev/null位置发送空白消息usign mutt。

$ mutt -s "Test Email" email_address < /dev/null

For example,

例如,

$ mutt -s "Greetings" james@example.com < /dev/null

Output

输出量

Mutt command can also be used to attach a file as follows.

Mutt命令还可以用于附加文件,如下所示。

$ echo "Message body" | mutt -a "/path/to/file.to.attach" -s "subject of message" -- email_address

For example,

例如,

$ echo "Hey guys! How's it going ?" | mutt -a report.doc -s "Notice !" -- james@jaykiarie.com

Output

输出量

4.使用mpack命令 (4. Using mpack command)

The mpack command is used to encode the file into MIME messages and sends them to one or several recipients, or it can even be used to post to different newsgroups.

mpack命令用于将文件编码为MIME消息,并将其发送给一个或几个收件人,甚至可以用于发布到不同的新闻组。

To install mpack in Debian / Ubuntu Systems run:

要在Debian / Ubuntu系统中安装mpack,请运行:

$ sudo apt install mpack

To install mpack in Redhat / CentOS Systems run:

要在Redhat / CentOS系统中安装mpack,请运行:

$ sudo yum install mpack

测试mpack命令 (Testing mpack command)

Using mpack to send email or attachment via command line is as simple as:

使用mpack通过命令行发送电子邮件或附件非常简单:

$ mpack -s "Subject here" -a file email_address

For example,

例如,

$ mpack -s "Sales Report 2019" -a report.doc james@jaykiarie.com

Output

输出量

5,使用sendmail (5.Using sendmail)

This command is another popular SMTP server used in many distributions.

此命令是许多发行版中使用的另一种流行的SMTP服务器。

To install sendmail in Debian/ Ubuntu Systems run:

要在Debian / Ubuntu系统中安装sendmail,请运行:

$ sudo apt install sendmail

To install sendmail in RedHat / CentOS Systems run:

要在RedHat / CentOS系统中安装sendmail,请运行:

$ sudo yum install sendmail

测试sendmail命令 (Testing sendmail command)

You can use the following instructions to send email using the sendmail command:

您可以按照以下说明使用sendmail命令发送电子邮件:

$ sendmail email_address < file

For example, I have created a file report.doc with the following text:

例如,我用以下文本创建了一个文件report.doc

Hello there !

The command for sending the message will be,

发送消息的命令为

$ sendmail < report.doc james@example.com

Output

输出量

You can use -s option to specify the email subject.

您可以使用-s选项指定电子邮件主题。

摘要 (Summary)

While the command line emails clients are a lot simpler and less computationally intensive, you can only use them to send email to personal email domains and not to Gmail or Yahoo domains because of extra authentication required.

尽管命令行电子邮件客户端非常简单且计算量较小,但是由于需要额外的身份验证,您只能使用它们将电子邮件发送到个人电子邮件域,而不能发送到Gmail或Yahoo域。

Also, you cannot receive emails from external SMTP servers. Generally, it’s a lot easier if you use GUI email clients like Thunderbird or Evolution to avoid undelivered emails problem.

另外,您也无法接收来自外部SMTP服务器的电子邮件。 通常,如果您使用Thunderbird或Evolution这样的GUI电子邮件客户端来避免未发送的电子邮件问题,则要容易得多。

翻译自: https://www.journaldev.com/26331/send-email-linux-command-line

linux命令行发送串口

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值