In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Xiaobian to share with you what are the ways to send mail under Linux, I believe most people do not know how, so share this article for your reference, I hope you have a lot of harvest after reading this article, let us go to understand it together!
5 Ways to Send Mail from Linux Command Line
When you need to create mail in a shell script, you need to use the command line to send mail knowledge. There are many commands in Linux that can be used to send mail. This tutorial contains five of the most popular command line mail clients, and you can choose one of them. These five commands are:
mail / mailxmuttmpacksendmailssmtp
working principle
Let me explain how the mail command delivers mail to recipients in Linux as a whole. Mail commands compose and send mail to a local mail transfer agent (MTA, e.g. sendmail, Postfix). The mail server communicates with the remote mail server to actually send and receive mail. The process below can be seen in more detail.
1)How to install mail/mailx command on Linux
The mail command is the most common command used by Linux terminals to send mail. mailx is an updated version of the mail command, based on Berkeley Mail 8.1, 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 certain interactive features, such as buffering mail messages, spam scoring, and filtering. On Linux distributions, the mail command is a soft link to the mailx command. You can install mail from the official distribution repository by running the following command.
For Debian/Ubuntu systems, install mailutils using APT-GET or APT commands.
$ sudo apt-get install mailutils
For RHEL/CentOS systems, use the YUM command to install mailx.
$ sudo yum install mailx
For Fedora systems, install mailx using the DNF command.
$ sudo dnf install mailx
1a) How to send mail using 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 command 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 e-mail on the Unix operating system, and supports color terminals, MIME, OpenPGP, and sorting by mail thread modes. You can install mutt from the official distribution repository by running the following command.
For Debian/Ubuntu systems, install mutt using APT-GET or APT commands.
$ sudo apt-get install mutt
For RHEL/CentOS systems, use the YUM command to install mutt.
$ sudo yum install mutt
For Fedora systems, install mutt using the DNF command.
$ sudo dnf install mutt
2b) How to send mail using mutt command on Linux
Mutt is just as easy to use. If you don't need to send an attachment, you can send the email using the mutt command format below:
$ echo "This is the mail body" | mutt -s "Subject" 2daygeek@gmail.com
If you want to send an attachment, use the mutt command format below:
$ echo "This is the mail body" | mutt -s "Subject" 2daygeek@gmail.com -a test1.txt
3)How to install mpack command on Linux
mpack is another popular command for sending mail on Linux terminals. The mpack program encodes named files in one or more MIME messages. The encoded message is sent to one or more recipients. You can install mpack from the official distribution repository by running the following command.
For Debian/Ubuntu systems, install mpack using APT-GET or APT commands.
$ sudo apt-get install mpack
For RHEL/CentOS systems, install mpack using the YUM command.
$ sudo yum install mpack
For Fedora systems, install mpack using the DNF command.
$ sudo dnf install mpack
3a) How to send mail using mpack command on Linux
MPack is also easy to use. If you don't need to send an attachment, you can send it using the mpack command format below:
$ 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.txt
4)How to install sendmail command on Linux
sendmail is a widely used general purpose SMTP server, you can also send mail from the command line with sendmail. You can install sendmail from the official distribution repository by running the following command.
For Debian/Ubuntu systems, install sendmail using APT-GET or APT commands.
$ sudo apt-get install sendmail
For RHEL/CentOS systems, install sendmail using the YUM command.
$ sudo yum install sendmail
For Fedora systems, install sendmail using the DNF command.
$ sudo dnf install sendmail
4a) How to send mail using sendmail command on Linux
Sendmail is also easy to use. Send mail using the sendmail command below.
$ echo -e "Subject: Test Mail\nThis is the mail body" > /tmp/send-mail.txt $ sendmail 2daygeek@gmail.com
< send-mail.txt 5) 如何在 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 ssmtp 5a) 如何在 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 The above is "What are the ways to send mail under Linux" All the contents of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.