Rotten mud: Configure msmtp + mutt in ubuntu to send emails, msmtpmutt

Source: Internet
Author: User
Tags gpg gpg encryption email account

Rotten mud: Configure msmtp + mutt in ubuntu to send emails, msmtpmutt

This article is sponsored by ilanniweb and first published onThe world

For more articles, follow my ilanniweb.

This article describes how to use msmtp + mutt to send emails in Linux. Of course, there are many tools for sending emails in Linux, such as sendmail + dovecot. However, their configurations are generally complex. Therefore, we use the simple msmtp + mutt combination to send emails.

The configuration of msmtp + mutt combination is simple and can be completed in just a few steps. Next we will introduce how to configure it in different steps.

PS: This article has passed all tests on ubuntu server 14.04 and centos6.6, and its related commands and configuration files can be directly used.

At the same time, we recommend that you operate the ubuntu system under the root user.

1. What is msmtp?

Msmtp is an SMTP client software dedicated to sending emails. It is released based on GPL. Supports TLS/SSL, DNS mode, IPv6, server-side authentication, and multiple users.

By default, msmtp sends emails to the SMTP server responsible for sending emails (for example, free email providers ).

Before using msmtp to send emails, you need to manually create an msmtp configuration file containing the email account, password, and other information, and make MUA (Mail User Agent client, here we use the Mail User proxy client mutt to enable the msmtp program, instead of/usr/sbin/sendmail, so that the mail client software can work better with msmtp.

Features supported by msmtp:

Compatible with sendmail interaction methods (command line options and exit code ).

Multiple verification methods.

TLS encrypted connections (including server certificate verification and verification that may need to be sent to the client certificate ).

Supports IDN (international domain name), DSN (delivery status notification), RMQS (enabling remote Message Queue) (only the keywords supported by ETRN), and PIPELINING (pipeline operation) to speed up email sending, support IPv6, support LMTP, and support for multiple email accounts.

Msmtp can also run on UNIX, Windows, DOS, and other systems.

Optional features are supported (depending on the additional libraries, see the instructions in INSTALL ).

Msmtp home page in http://msmtp.sourceforge.net/

Ii. Install msmtp

The above describes the features of msmtp. Now we will introduce how to install msmtp.

For msmtp installation, we can install centos and ubuntu based on the platform we usually use, and install yum, apt-get, and source code based on different installation methods. The following describes how to install msmtp.

2.1 yumInstallation Method

If the yum method is used for installation, We need to install additional epel sources. As follows:

Rpm-ivh http://mirrors.aliyun.com/epel/6/x86_64/epel-release-6-8.noarch.rpm

Ll/etc/yum. repos. d

Start msmtp installation as follows:

Yum-y install msmtp

After msmtp is installed, check the msmtp help information as follows:

Msmtp -- help

We can see that msmtp has many options.

2.2 apt-getInstall

Installing msmtp in ubuntu is easy. You can directly use apt-get to install msmtp. As follows:

Sudo apt-get-y install msmtp

After msmtp is installed, you can view the help information as follows:

Msmtp -- help

We can see that msmtp has many options.

2.3Source code Installation

Msmtp installed in yum or apt-get mode is not the latest version. If you want to use the latest version of msmtp, you can only install it in source code mode.

The latest version of msmtp is 1.6.2. Here, we use the ubuntu platform as an example. The download source code is as follows:

Wget http://nchc.dl.sourceforge.net/project/msmtp/msmtp/1.6.2/msmtp-1.6.2.tar.xz

Decompress msmtp-1.6.2.tar. xz, as follows:

Xz-d msmtp-1.6.2.tar.xz

Tar-xf msmtp-1.6.2.tar

Cd msmtp-1.6.2/

Before compiling and installing msmtp, We need to install the corresponding software package. As follows:

Sudo apt-get-y install gcc libglib2.0-dev

NOTE: If msmtp is installed in the source code of ubuntu, the above software package libglib2.0-dev must be installed. Otherwise, compilation cannot be performed.

To use centos, install the following software packages:

Yum-y install gcc-c ++ gnutls-devel gnutls-utils openssl-devel libidn-devel

Download, start compilation, and install msmtp, as shown below:

./Configure -- bindir =/usr/bin/

Sudo make

Sudo make install

After the installation is complete, let's check it out. As follows:

Which msmtp

Msmtp -- help

You can see that msmtp has been installed successfully.

3. Use msmtp

After msmtp is installed, let's test its mail sending function.

3.1Create an msmtp configuration file

Before testing msmtp, We need to configure the configuration file for msmtp mail sending. As follows:

Sudo vi/etc/msmtprc

Ults

Tls on

Logfile/var/log/msmtp. log

Account ilanni

Host smtp.126.com

Port 25

From duanzhanling@126.com

Auth login

Tls off

User duanzhanling@126.com

Passwordeval "gpg -- no-use-agent -- passphrase = ilanni-q -- no-tty-d/root/pass. gpg"

Account default: ilanni

Now let's explain the meaning of each option in the above command.

Logfile indicates logging.

Account ilanni defines the name of the sent email of ilanni.

Host smtp.126.com indicates the SMTP server address.

Port 25 indicates the port of the SMTP server.

From duanzhanling@126.com represents the sent mail address.

Auth login uses the login authentication method.

Tls off indicates that tls is not used.

Passwordeval indicates the login password for the mailbox duanzhanling@126.com.

If multiple email accounts are defined, you can use account default to specify the default email sending name.

For more information about gpg encryption and decryption, refer to this article: learning about gpg encryption and decryption software.

3.2Test msmtp to send mail

As we mentioned earlier, msmtp is also an SMTP client software and can also be used to send emails. Now let's test it.

To test msmtp, run the following command:

Echo "Subject: test msmtp \ r \ n \ r \ nThis is a test for ilanni." | msmtp-d-C/etc/msmtprc-t duanzhanling@126.com

The Subject parameter specifies the topic. \ r \ n is followed by the email content.-d indicates to print the debug information, and-C indicates the configuration file, -t specifies the recipient's email address.

After the preceding command is executed, you can view the sending log records in the logfile. As follows:

Cat/var/log/msmtp. log

We can see that the email has been successfully sent.

Log on to the mail client and check whether you have received the email you just sent:

We can see that the email we just sent has been received.

4. What is mutt?

Mutt is an e-mail program in linux. It is different from common Windows Mail programs. It is not an all-encompassing hodgedge. You may even find that it does not directly send emails. It never edits emails by itself, and it never encrypts and digitally signs emails by itself. Mutt is more like a file manager, but it manages emails. Its functions are implemented by using the most powerful programs, which conforms to the UNIX Design Philosophy:

When mutt needs to edit the email, it may call editors such as vi, vim, and emacs.

When mutt needs to send a mail, it puts the mail to be sent in the sendmail queue, and nothing else is done.

When a digital signature is required, mutt will hand over the letter to programs such as GnuPG for processing and then send it out again.

How can I receive emails? Mutt won't go to the POP server to get the mail by yourself. You need a fetchmail program to help you retrieve the email from the POP server and forward it to your sendmail mailbox. It seems that your host has become a complete UNIX Network workstation.

Mutt supports most mail formats, including mbox, Maildir, and protocol. For example, POP3 and IMAP. It also supports MIME, PGP/GPG, and S/MIME integration.

MuttIt is designed to act as the Mail User proxy (MUA), so it cannot be used alone to send mail. If you want to send an email, it must be implemented with the mail Transmission proxy ., For example, popular sendmail, exim4, and postfix. It also relies on other tools to write and filter emails.

Mutt has hundreds of configuration items and commands. It allows you to change all key bindings and set keyboard macros to complete complex tasks, as well as configure colors and page la S. With the so-called hooks variable, many configurations can be changed based on conditions, such as the current mailbox or external mail recipient. There are many patches and extensions for enhanced features, such as NNTP.

Mutt is completely controlled by the keyboard and supports mail threading. Therefore, users can easily browse lengthy discussions. Mutt's new mail writing is completed by the external text editor. This is quite different from the built-in editor of other mail client tools.

5. Install mutt

Mutt installation can be divided into yum, apt-get, and source code installation. Here, we do not use the source code for installation, but directly use the yum and apt-get methods.

Install mutt in ubuntu as follows:

Sudo apt-get install-y mutt

Install mutt in centos as follows:

Yum-y install mutt

After the installation is complete, let's check what files are installed by mutt, as shown below:

Dpkg-L mutt | tac

The configuration file of mutt is Muttrc. Now let's check the configuration file Muttrc for mutt, as shown below:

Grep-vE '^ # | ^ $'/etc/Muttrc

We can see that the mutt configuration file Muttrc has many options. Here, we only configure required options. As follows:

Sudo vi/etc/Muttrc

Set sendmail = "/usr/bin/msmtp"

Set use_from = yes

Set realname = "muddy cloud monitoring platform"

Set editor = "vi"

In the above configuration options, sendmail sets the client program for sending mails, and editor sets the editor series called by mutt.

6. Use mutt

After mutt is installed and configured, we can use mutt to send emails. Run the following command to test the function:

Echo "here is the body" | mutt-s "ilanni-test" duanzhanling@126.com

Cat/var/log/msmtp. log

The above command means to send a message here is the body, subject is ilanni-test mail to the duanzhanling@126.com user.

Through, we can clearly see that mutt has successfully sent an email to the duanzhanling@126.com user by calling msmtp.

Now we can view this email in the duanzhanling@126.com mailbox, as follows:

We can see that mutt has successfully sent an email.

In addition to sending emails using the preceding commands, you can save the content of the emails to a file and then send them as follows.

Cat testmutt | mutt-s "ilanni-test" duanzhanling@126.com

7. other mutt usage

In chapter 6, we can see that mutt indeed sends an email by calling msmtp. Now let's take a look at other mutt usage methods.

7.1Mass mailing

Mutt can send emails by group. Here we have two emails for testing.

Use mutt to send messages to both lanni654321@126.com and duanzhanling@126.com mailboxes at the same time with the following command:

Echo "lanni -- here is the body" | mutt-s "ilanni-test" lanni654321@126.com duanzhanling@126.com

We can see that mutt does support mass mailing.

7.2Send attachment

Use mutt to send messages to both lanni654321@126.com and duanzhanling@126.com mailboxes, and add the attachment testilanni1, testilann2. The content of testilanni1 and testilann2is this is a test. As follows:

The mutt command is as follows:

Echo "lanni -- here is the test attachment" | mutt-s "ilanni-test" lanni654321@126.com duanzhanling@126.com-a testilanni1 testilannickel

The function of sending attachments by mutt requires the cooperation of parameter-.

We can see that mutt has successfully sent attachments.

7.3CC email

Use mutt to send a mail to the duanzhanling@126.com mailbox, while CC the mail to the lanni654321@126.com, and add the attachment testilanni1, testilann2. The command is as follows:

Echo "lanni -- here is the test CC function" | mutt-s "ilanni-test" duanzhanling@126.com-c lanni654321@126.com-a testilanni1 testilannickel

The mutt CC function requires the cooperation of parameter-c.

Through, we can see that the mail has been successfully copied to the lanni654321@126.com user.

7.4BCC

Use mutt to send an email to the lanni654321@126.com mailbox, bcc It To The duanzhanling@126.com, and add the attachment testilanni1, testilann2. The command is as follows:

Echo "lanni -- here is the test BCC function" | mutt-s "ilanni-test" lanni654321@126.com-B duanzhanling@126.com-a testilanni1 testilannickel

The mutt BCC function requires the cooperation of parameter-B.

Through, we can see that while the mail is sent to the lanni654321@126.com, it is indeed secretly sent to the duanzhanling@126.com user.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.