L05-Linux deployment msmtp + mutt send mail, msmtpmutt

Source: Internet
Author: User

L05-Linux deployment msmtp + mutt send mail, msmtpmutt

I. Preface

First of all, you have to understand the process of sending an email, the following section of the theory Excerpted from the official website of Liao Xuefeng https://www.liaoxuefeng.com/article/00137387674890099a71c0400504765b89a5fac65728976000

"""

It is usually easy to use Email, but the Internet mail system is connected by several complex parts. for end users, we are familiar with Outlook, foxmail is used for receiving and sending emails.MUA: Mail User Agent, Mail User Agent.

Instead of sending the email directly to the recipient, MUA usesMTA: Mail Transfer Agent, which is used by the Mail transmission Agent for transmission. Sendmail and Postfix assume the role of MTA.

After an email is sent from MUA, it may be passed through one or more MTA and eventually arriveMDA: Mail Delivery Agent, Mail Delivery Agent. After the Mail arrives at the MDA, it is stored in a file or a special database. We call the mailbox where the long-lived Mail is saved.

Once the email arrives at the mailbox, it will remain unchanged. When the user picks it up through MUA, it is the process of receiving the mail using software such as Outlook and Foxmail.

So the process of an email is:

Sender: MUA -- send --> MTA-> several MTA...-> MTA-> MDA <-- receive -- MUA: recipient

The protocols used between MUA and MTA and between MTA are SMTP protocols. When receiving emails, the most common protocols used between MUA and MDA are POP3 or IMAP.

It should be noted that professional email service providers have a large number of machines to serve users. Therefore, MTA and MDA are generally not the same server. Therefore, in Outlook and other software, enter the SMTP sending server address and POP3 receiving server address respectively.

"""

 

This blog post: https://www.cnblogs.com/DLHe/p/8457393.html is also very clear about the mail process.

We can see from the above that the Outlook and Foxmail we are familiar with are mail clients and provide MUA functions. Some e-mail service providers, such as Netease And QQ, the MTA function is provided.

It must be clarified that the msmtp + mutt deployed this time is actually a MUA mail client like Foxmail, but it runs on linux. If sendmail or postfix is deployed on linux, the mail server serves as the MTA function.

 

Next is the implementation step.

Deployment environment successfully tested:RHEL6.5 and CentOS6.5. Of course, machines can be connected to the Internet.

 

Ii. Install msmtp

Msmtp is an SMTP client that can send mail to the SMTP server, the official website address is http://msmtp.sourceforge.net/index.html.

1.Download the msmtp File

Cd/usr/local/src

Wget http://sourceforge.net/projects/msmtp/files/msmtp/1.4.32/msmtp-1.4.32.tar.bz2/download

 

2.Decompress the file

Tar jxvf msmtp-1.4.32.tar.bz2

 

3.Go to the decompressed file, and then install the typical source code in three steps./configure, make, and make install.

3.1 execute./configure and generate Makefile to prepare for the next compilation. -- prefix = is followed by the path to install msmtp, which has nothing to do with the directory where the current mstmp source code is located.

Cd msmtp-1.4.32

./Configure -- prefix =/usr/local/msmtp

3.2 make & make install, compile and install. You can also execute these two steps separately.

 

4.Create the etc directory under the/usr/local/msmtp/installation directory and create an msmtp file under the etc directory. This file is used to configure some basic information about mail sending.

Mkdir-p/usr/local/msmtp/etc

Vim/usr/local/msmtp/etc/msmtprc

#Add the following content:

Account default

Host smtp.163.com

Port 25

From xxx@163.com // enter the actual 163 mailbox according to the actual situation

Auth login

Tls off

User xxx // Email user name, which is xxx rather than xxx@163.com

Password xxx // note that the password here may beAuthorization codeFor example, the authorization code must be entered in the 163 email address, as shown in figure

Logfile/var/log/mmlog

 

 

Note:As mentioned above, the combination of msmtp + mutt is the same as Foxmail, which is the mail client. We know that in Windows, if Foxmail is used to send emails, you must first log on to Foxmail with one of your accounts before you can create new emails under this client. In this step, the role of this file configuration is to log on to the msmtp client with an account in linux. Here I use 163 Netease mailbox. If I want to use QQ mailbox, I need to modify it separately.

 

The Configuration During the test is as follows:

 

(Note: The Directory is a bit messy. It is the installation directory deployed in the actual production environment, not the above execution. in the/configure command, the/usr/local/msmtp specified by the -- prefix parameter does not matter. Remember that the file is actually in the installation directory specified by the prefix parameter !)

 

5.Grant permissions to log files:

Chmod 777/var/log/mmlog

 

6.Assign permissions to the msmtprc file of the configuration file. Because the file contains the plaintext password of the mailbox, it must be set to non-readable.

Chmod 600 msmtprc

 

7.In this case, you can create a soft connection about/usr/local/msmtp/bin/msmtp in the/usr/bin/directory. In this way, you can directly run the msmtp command on the server to execute msmtp.

Ln-s/usr/local/msmtp/bin/msmtp/usr/bin/msmtp

 

8.Test msmtp(Similarly, the email address depends on the actual situation, but it must be the same as the email address in the/usr/local/msmtp/etc/msmtprc configuration file.)

(1) If no soft connection is made in step 1:

/Usr/local/msmtp/bin/msmtp xxx @163. ComHello, test ctrl d

(2) If a soft connection is established, the test command can be:

Msmtp xxx @163. ComHello, test ctrl d

#Check whether the log is successfulCat/usr/local/msmtp. log

#Check the email 163 to see if the email has been received.

For example, you can receive emails at this time, but there is no content in the emails. This is no problem.

Now, msmtp installation is complete.

 

 

3. Install Mutt

Mutt is an Email client. It cannot directly send emails. It is more responsible for email management and can be used together with msmtp. Official site for http://www.mutt.org/

To learn more about the use of Mutt and msmtp, you can view the following address: http://msmtp.sourceforge.net/doc/msmtp.html#Using-msmtp-with-Mutt

 

1. Mutt Installation Method 1: install and configure mutt in yum mode (tested successfully)

1.1yum install-y mutt

 

1.2 edit the/etc/Muttrc File(Note,The Muttrc file already exists in the/etc directory, but the following content is appended to the end of the file)

Vim/etc/Muttrc

# Enter the following content:

Set sendmail = '/usr/bin/msmtp'#Note: The reason for writing this is that a soft connection is made during msmtp configuration.# Ln-s/usr/local/msmtp/bin/msmtp/usr/bin/msmtp

Set use_from = yes

Set realname = 'yourname'# RealnameYou can set it as needed. In this way, when you send an email to someone else, the recipient can see that the title of the sender is set here. For details, refer to the settings below and the final image display results.

Set from = user@163.comset

Envelope_from = yes

Auto_view text/html

Set charset = 'utf-8'

Set send_charset = 'utf-8'

Set locale = 'zh _ CN.UTF-8'

Set content_type = 'text/html \; charset = UTF-8'

 

Set rfc2047_parameters = yes

The configuration is as follows:

However, a rough error occurs during the mail sending test. The mail can be sent, but an error is reported after the command is executed: source: errors in/etc/Muttrc.

Set sendmail = "/usr/bin/msmtp"

Set use_from = yes

Set realname = "Zabbix Server"

Set editor = "vim"

Set from = 182xxxx7782@163.com

 

1.3 after configuration is complete, test:

(1) simple test (send to yourself ):Echo "TEST test" | mutt-s "DT_ZABBIX_SERVER_TEST" 182xxxx7782@163.com

 

(2) Add an attachment for testing (send it to yourself ):Echo "content: TEST test" | mutt-s "Topic: DT_ZABBIX_SERVER_TEST"-a/data/suxy_remark.txt 182xxxx7782@163.com

Sending error, error reported: Can't stat 182xxxx7782@163.com: No such file or directory

As shown, this is because the 182xxxx7782@163.com is behind the-a command, so mutt treats the 182xxxx7782@163.com as an attachment, so replace the-a command with a location, put it at the end (in fact, the usage of this command does require that the-a parameter be placed at the end of the command ):

Echo "content: TEST test" | mutt-s "Topic: DT_ZABBIX_SERVER_TEST" 182xxxx7782@163.com-a/data/suxy_remark.txt

Sent successfully!

In fact, you can also use the following command to write the email address after mutt, And put parameters such as-s and-a in the back.

Echo "content: TEST test" | mutt 182xxxx7782@163.com-s "Topic: DT_ZABBIX_SERVER_TEST"-a/data/readme.txt

 

(3) Of course, you can also send emails to other types of mailboxes, such as QQ and company mailboxes.:

Echo "content: TEST test" | mutt-s "Topic: DT_ZABBIX_SERVER_TEST" 98xxxx3649@qq.com-a/usr/local/suxy_remark.txt

 

 

2. MuttInstallation Method 2: Install Mutt in source code mode (the test fails, but the test method is incorrect ..)

Cd/usr/local/src

Wget ftp://ftp.mutt.org/pub/mutt/mutt-1.5.24.tar.gz

Tar xvf mutt-1.5.24.tar.gz

Cd mutt-1.5.24

./Configure -- prefix =/usr/local/mutt

 

Make&&MakeInstall

 

 

Configure Mutt

Vim/usr/local/mutt/etc/Muttrc

# Add the following lines at the end:

Set sendmail = "/usr/local/msmtp/bin/msmtp"

Set use_from = yes

Set realname = "xxx"

Set from = xxx@163.com

Set envelope_from = yes

 

Test Mutt

Echo "hello, world" |/usr/local/mutt/bin/mutt-s "test mail" xxx@163.com # The above statement will send a message titled "test mail ", the content is "hello, world", the recipient is a xxx@163.com message, you can check whether the mailbox can receive the mail

Commands used in actual testing:

Echo "Test from Zabbix Server" |/usr/local/mutt/bin/mutt-s "zabbixTest" 182xxxx7782@163.com

But if you use the above command to send it, it will send an e-mail to both-s@zabbix.localhost and zabbixtest@zabbix.localhost and 182xxxx7782@163.com, change to the following command will only send to 182, but no subject

Echo "Test from Zabbix Server" |/usr/local/mutt/bin/mutt 182xxxx7782@163.com

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.