Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to send mail on the Linux command line

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how to send e-mail on the Linux command line", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to send mail on the Linux command line" this article.

When you need to create an email in a shell script, you need to use the knowledge of sending mail on the command line. There are many commands in Linux to send mail. The five most popular command line mail clients are included in this tutorial, and you can choose one of them. The five commands are:

Mail / mailx

Mutt

Mpack

Sendmail

Ssmtp

working principle

Let me first explain how the mail commands in Linux deliver the message to the recipient as a whole. Mail commands compose messages and send them to a local mail transfer agent (MTA, such as sendmail, Postfix). The mail server and the remote mail server communicate to actually send and receive mail. The following process can be seen in more detail.

1) how to install mail/mailx commands on Linux

The mail command is the most common command used by Linux terminals to send mail. Mailx is a newer version of the mail command based on Berkeley Mail 8.1 and is intended to provide the functionality of the POSIX mailx command and support MIME, IMAP, POP3, SMTP, and S/MIME extensions. Mailx is more powerful in some interactive features, such as buffering email messages, spam scoring, and filtering. On the Linux distribution, the mail command is a soft link to the mailx command. You can run the following command to install the mail command from the official distribution repository.

For Debian/Ubuntu systems, use the APT-GET command or the APT command to install mailutils.

$sudo apt-get install mailutils

For RHEL/CentOS systems, use the YUM command to install mailx.

$sudo yum install mailx

For Fedora systems, use the DNF command to install mailx.

$sudo dnf install mailx1a) how to send mail using the mail command on Linux

The mail command is easy to use. If you don't need to send an attachment, you can send an email using the following mail command format:

$echo "This is the mail body" | mail-s "Subject" 2daygeek@gmail.com

If you want to send an attachment, use the following mail command format:

$echo "This is the mail body" | mail-a test1.txt-s "Subject" 2daygeek@gmail.com

-a: used to add attachments to Red Hat-based systems.

-A: used to add attachments to Debian-based systems.

-s: specifies the message title.

2) how to install mutt commands on Linux

Mutt is another popular command to send mail on Linux terminals. Mutt is a small but powerful text-based program for reading and sending email under the unix operating system, and supports color terminals, MIME, OpenPGP, and sorting by email thread mode. You can run the following command to install the mutt command from the official distribution repository.

For Debian/Ubuntu systems, use the APT-GET command or the APT command to install mutt.

$sudo apt-get install mutt

For RHEL/CentOS systems, use the YUM command to install mutt.

$sudo yum install mutt

For Fedora systems, use the DNF command to install mutt.

$sudo dnf install mutt2b) how to send mail using the mutt command on Linux

Mutt is just as easy to use. If you don't need to send an attachment, you can send an email using the following mutt command format:

$echo "This is the mail body" | mutt-s "Subject" 2daygeek@gmail.com

If you want to send an attachment, use the following mutt command format:

$echo "This is the mail body" | mutt-s "Subject" 2daygeek@gmail.com-a test1.txt3) how to install the mpack command on Linux

Mpack is another popular command to send mail on Linux terminals. The mpack program encodes the named file in one or more MIME messages. The encoded message is sent to one or more recipients. You can run the following command to install the mpack command from the official distribution repository.

For Debian/Ubuntu systems, use the APT-GET command or the APT command to install mpack.

$sudo apt-get install mpack

For RHEL/CentOS systems, use the YUM command to install mpack.

$sudo yum install mpack

For Fedora systems, use the DNF command to install mpack.

$sudo dnf install mpack3a) how to send mail using the mpack command on Linux

Mpack is also easy to use. If you don't need to send an attachment, you can send an email using the following mpack command format:

$echo "This is the mail body" | mpack-s "Subject" 2daygeek@gmail.com

If you want to send an attachment, use the following mpack command format:

$echo "This is the mail body" | mpack-s "Subject" 2daygeek@gmail.com-a test1.txt4) how to install the sendmail command on Linux

Sendmail is a widely used general-purpose SMTP server, and you can also send emails using sendmail from the command line. You can run the following command to install the sendmail command from the official distribution repository.

For Debian/Ubuntu systems, use the APT-GET command or the APT command to install sendmail.

$sudo apt-get install sendmail

For RHEL/CentOS systems, use the YUM command to install sendmail.

$sudo yum install sendmail

For Fedora systems, use the DNF command to install sendmail.

$sudo dnf install sendmail4a) how to send mail using the sendmail command on Linux

Sendmail is also easy to use. Use the following sendmail command to send mail.

$echo-e "Subject: Test Mail\ nThis is the mail body" > / tmp/send-mail.txt$ sendmail 2daygeek@gmail.com

< send-mail.txt5) 如何在 Linux 上安装 ssmtp 命令 ssmtp 是类似 sendmail 的一个只发送不接收的工具,可以把邮件从本地计算机传递到配置好的 邮件主机(mailhub)。用户可以在 Linux 命令行用 ssmtp 把邮件发送到 SMTP 服务器。可以运行下面的命令从官方发行版仓库安装 ssmtp 命令。 对于 Debian/Ubuntu 系统,使用 APT-GET 命令 或 APT 命令安装 ssmtp。 $ sudo apt-get install ssmtp 对于 RHEL/CentOS 系统,使用 YUM 命令 安装 ssmtp。 $ sudo yum install ssmtp 对于 Fedora 系统,使用 DNF 命令 安装 ssmtp。 $ sudo dnf install ssmtp5a) 如何在 Linux 上使用 ssmtp 命令发送邮件 ssmtp 同样简单易用。使用下面的 ssmtp 命令格式发送邮件。 $ echo -e "Subject: Test Mail\nThis is the mail body" >

/ tmp/ssmtp-mail.txt$ ssmtp 2daygeek@gmail.com < / tmp/ssmtp-mail.txt is all the contents of the article "how to send an email at the Linux Command Line". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report