Slime: Configure Msmtp+mutt to send mail under Ubuntu

Source: Internet
Author: User
Tags gpg gpg encryption message queue mail account

This article is sponsored by Ilanniweb , starting in Slime Line the world

To get more articles, you can follow my ilanniweb.

This article mainly describes how to use Msmtp+mutt to send mail under Linux, of course, there are many tools for sending mail under Linux, such as Sendmail+dovecot. But they are generally more complex to configure, so let's use a simple msmtp+mutt combination to send the message.

The Msmtp+mutt combination configuration is simple and takes just a few steps to complete. Let's step through how to configure this.

PS: This article has been fully tested on Ubuntu server 14.04 and centos6.6, and its related commands and configuration files can be used directly.

At the same time Ubuntu system, it is recommended to operate under the root user.

First, what is MSMTP

MSMTP is an SMTP client software specifically responsible for mail delivery and is distributed based on the GPL. Support TLS/SSL, DNS mode, IPV6, server-side authentication, multi-user and other features.

By default, MSMTP sends the message to the SMTP server responsible for sending the message (for example, the free mailbox vendor).

Before using MSMTP to send a message, you need to manually create a mail account and password and other related information msmtp configuration file, and let Mua ( Mail User Agent client , where we use the mutt This mail user Agent client) to enable the MSMTP program, not/usr/sbin/sendmail, so that the mail client software and MSMTP better work together.

Features Supported by MSMTP:

Compatible with SendMail interaction (command-line options and exit codes).

Multiple authentication methods.

TLS encrypted connections that contain server certificate validation and authentication that may need to be sent to the client certificate.

Support IDN (internationalized Domain name), support DSN (delivery status notification), support RMQS (open remote Message queue) (ETRN supported keywords only), support pipelining (pipelining) to increase the speed of sending mail, support IPV6, support LMTP, support multi-mail account.

MSMTP can also be run on Unix-like, Windows-and DOS-like systems.

Optional feature support (depending on the additional library, see the instructions for use in the install).

Msmtp's homepage is located in http://msmtp.sourceforge.net/

Second, installation msmtp

The related features of MSMTP are described above, and we will now describe how to install MSMTP.

MSMTP installation We are based on the normal use of the platform is divided into the installation of CentOS and Ubuntu platform, and according to the different installation methods are divided into Yum, apt-get and source installation, the following respectively.

2.1 Yum Mode installation

If the Yum mode is installed, 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 installing MSMTP, as follows:

Yum-y Install MSMTP

MSMTP after the installation is complete, we will review the following MSMTP help information, as follows:

MSMTP--help

Through, we can clearly see that MSMTP has a lot of options.

2.2 Apt-get installation

Installing MSMTP under Ubuntu is easy and installs directly using Apt-get. As follows:

sudo apt-get-y install msmtp

MSMTP after installation, we choose to see the following help, as follows:

MSMTP--help

Through, we can clearly see that MSMTP has a lot of options.

2.3 Source Installation

Neither Yum nor Apt-get installed MSMTP is the latest version, if you want to use the latest version of MSMTP, we can only use source mode installation.

MSMTP the latest version is 1.6.2, here is the Ubuntu platform for example, download the source code as follows:

wget Http://nchc.dl.sourceforge.net/project/msmtp/msmtp/1.6.2/msmtp-1.6.2.tar.xz

Unzip the 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 we start compiling and installing MSMTP, we also need to install the appropriate packages. As follows:

sudo apt-get-y install gcc Libglib2.0-dev

Note: Ubuntu under the source installation MSMTP, the above package Libglib2.0-dev must be installed otherwise cannot be compiled.

If it is a CentOS platform, you need to install the following packages:

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

Download start compiling the installation msmtp as follows:

./configure--bindir=/usr/bin/

sudo make

sudo make install

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

Which MSMTP

MSMTP--help

You can see that the MSMTP has been installed successfully.

Third, the use of MSMTP

MSMTP after the installation, we test the ability to send mail.

3.1 Create a msmtp configuration file

Before we test the MSMTP, we need to configure the configuration file for Msmtp to send the message. As follows:

sudo VI/ETC/MSMTPRC

Defaults

TLS on

Logfile/var/log/msmtp.log

Account Ilanni

Host Smtp.126.com

Port 25

From [email protected]

Auth Login

TLS off

User [email protected]

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

Account Default:ilanni

Now explain the meanings of the various options in the above command.

LogFile indicates logging.

Account Ilanni defines the name of a ilanni sent message.

Host smtp.126.com represents the server address for SMTP.

Port 25 represents the ports of the SMTP server.

From [email protected] Indicates the email address sent.

AUTH Login uses login authentication method.

TLS off means that TLS is not used.

Passwordeval means [email protected] The login password for this email.

If you define multiple mailbox accounts, we can use account default to specify the default send message name.

About GPG encryption and decryption can refer to this article " Slime: GPG plus decryption software learning ."

3.2 test msmtp Send mail

As we've described earlier, MSMTP is also an SMTP client software that can be used to send mail, and now we're going to test it.

To test the MSMTP, we can use the following command:

echo "Subject:test Msmtp\r\n\r\nthis is a test for Ilanni." |msmtp-d-c/etc/msmtprc-t [email protected]

Parameter subject specifies the subject, \r\n\r\n followed by the message content,-D indicates the print debug information,-C indicates the configuration file,-t specifies the recipient's email address.

After the above command has been executed, we can view the send log records inside the logfile. As follows:

Cat/var/log/msmtp.log

Through, we can obviously see that the message has been sent successfully.

Below we will log in to the mail client to see if you receive the message you just sent, as follows:

Through, we can obviously see just send the mail that we have received.

Iv. What is Mutt

Mutt is an email program under Linux that is different from a typical Windows Mail program and is not an all-encompassing hodgepodge. You may even find that it does not send a message directly, it never edits the message itself, it never encrypts and digitally signs the message itself. Mutt is more like a file manager, except that it manages email. Its functionality is achieved through the most powerful programs, which are in line with UNIX design ideas:

When Mutt needs to edit a message, it may call VI, VIM, Emacs and other editors.

When Mutt needs to send a letter, it puts the letters that need to be sent to the SendMail queue, and everything else does.

When a digital signature is required, Mutt sends the letter to a program such as GnuPG to handle it before sending it out.

How do you collect e-mails? Mutt is not going to the POP server to pick up the mail, you need a fetchmail program, to help you get the email from the POP server, and then forwarded to their own SendMail mailbox. This looks like your host becomes a complete UNIX network workstation.

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

Mutt designed to serve as a mail user agent (MUA), so it cannot be used alone to send messages. If you want to send a message, it needs to be implemented in conjunction with a mail transfer agent. , for example: Popular SendMail, EXIM4, Postfix and so on. It also relies on other tools to compose and filter messages.

Mutt has hundreds of configuration items and commands. It allows changing all key bindings and setting keyboard macros to complete complex tasks, as well as configuring color and interface layouts. With the so-called hooks variables, many configurations can be based on conditional changes, such as the current mailbox or outgoing mail recipient. There are many enhancements to patches and extensions, such as NNTP.

The mutt is fully keyboard-controlled and supports mail threading. This makes it easy for users to navigate through lengthy discussions. Mutt's new mail compose is done by an external text editor. This is very different from the built-in editor for other mail client tools.

V. Installation of Mutt

Mutt installation We can be divided into Yum, apt-get and source installation. Here we do not use the source code installed, directly using the Yum and Apt-get way.

Install mutt under Ubuntu, as follows:

sudo apt-get install-y Mutt

Install mutt under CentOS, as follows:

Yum-y Install Mutt

Once the installation is complete, let's look at what files are installed in Mutt, as follows:

Dpkg-l Mutt |tac

Through, we can see that the mutt configuration file is muttrc. Now look at the configuration file muttrc for under decade Mutt, as follows:

Grep-ve ' ^#|^$ '/etc/muttrc

Through, we can see that mutt's configuration file muttrc has many options. Here, we only configure the necessary options. As follows:

sudo vi/etc/muttrc

Set sendmail= "/usr/bin/msmtp"

Set Use_from=yes

Set realname= "Slime Cloud monitoring Platform"

Set editor= "VI"

In the configuration options above, SendMail sets the client program that sends the message, and editor sets the mutt call to the editor.

Vi. use of Mutt

Once the mutt is installed and configured, we can use Mutt to send mail. Now test with the following command:

echo "Here is the body" |mutt-s "ilanni-test" [email protected]

Cat/var/log/msmtp.log

The above command means to send a content is here is the text, the subject is ilanni-test mail to [email protected] this user.

Through, we can obviously see Mutt has successfully sent a message by calling MSMTP to [email protected] this user.

Now we are logged in [email protected] This email to view this email, as follows:

Through, we can clearly see that mutt has indeed successfully sent the mail.

In addition to sending messages via the above command, we can also save the contents of the message to a file and send it in the form below.

Cat testmutt|mutt-s "Ilanni-test" [email protected]

Vii. Other uses of mutt

In the sixth chapter, we can see that mutt does send messages by calling MSMTP. Now let's look at other ways to use mutt.

7.1 Bulk Mail

Mutt can send bulk mail, here we have two messages as an example to test.

Use mutt at the same time to [email protected] and [email protected] These two mailboxes to send mail, the command is as follows:

echo "Lanni--here is the text" |mutt-s "ilanni-test" [email protected] [email protected]

Through, we can see that mutt really can support bulk mail.

7.2 Send Attachments

Use mutt to send messages to both email protected and [email protected] and add attachments testilanni1,testilanni2. The contents of the annexes Testilanni1 and Testilanni2 are this is a test. As follows:

The mutt command is as follows:

echo "Lanni--here is the test accessory" |mutt-s "ilanni-test" [email protected] [email protected]-a testilanni1& #160; Testilanni2

The Mutt send attachment function requires a mate of parameter-a.

Through, we can clearly see that Mutt has successfully sent the attachment.

7.3 cc Mail

Use mutt to send email to [email protected], and copy the email to [email protected], and add the attachment testilanni1,testilanni2. The command is as follows:

echo "Lanni--here is the test cc function" |mutt-s "ilanni-test" [email protected]-c [email protected]-a testilanni1& #160; Testilanni2

The Mutt cc feature requires a mate of parameter-C.

Through, we can see the mail has been successfully copied to [email protected] this user.

7.4 bcc Mail

Use Mutt to send mail to [email protected] This email, and also to [email protected], and add the attachment testilanni1,testilanni2. The command is as follows:

echo "Lanni--here is the test secret delivery function" |mutt-s "ilanni-test" [email protected]-b [email protected]-a testilanni1& #160; Testilanni2

The mutt feature requires a mate of parameter-B.

Through, we can see the e-mail sent to [email protected], but also really secretly sent to the [email protected] this user.

Slime: Configure Msmtp+mutt to send mail under Ubuntu

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.