centos configure mutt and msmtp to deliver mail

  • 2020-06-19 12:31:43
  • OfStack

1. Install mutt


yum install mutt -y

2. Configuration mutt


vim /etc/Muttrc 

Find the following lines in it and change the contents to your own (the following lines are distributed in different places, please be patient and remove the # sign at the beginning of the line)


set from=" Send email address " 
set sendmail="/usr/local/msmtp/bin/msmtp" 
set use_from=yes 
set realname=" Name of sender " 
set editor="vim" 

Download and unzip msmtp


wget http://downloads.sourceforge.net/msmtp/msmtp-1.4.30.tar.bz2?big_mirror=0 
 
tar xf msmtp-1.4.30.tar.bz2 

Depending on the system, wget and bzip2 need to be installed


yum install wget bzip2 -y

4. Compile msmtp

Once unzipped, go to the unzipped directory and run the following statement


./configure --prefix=/usr/local/msmtp
make
make install

5. Configuration msmtp


cd /usr/local/msmtp
mkdir etc
cd etc
vim msmtprc

Add the following to the file:


defaults 
# The specified log The location of the  
logfile /usr/local/msmtp/msmtp.log 
# The SMTP server of the provider. 
account test 
# SMTP Mail server address  
host smtp.qq.com 
#  To send an email Email 
from xxxxx@qq.com 
auth login 
#  The account used to send the email  
user xxxxxx@qq.com 
#  The login password for the account used to send the email  
password 123456 
# Set a default account 
account default: test 

Save the exit

Since the password is in clear text, it is best to change the file permissions here: chmod 600 msmtprc

Test 6.

Once configured according to the above configuration, you can test and run the following statement


echo " Email content " |mutt -s " Email subject "  Addressee's mailbox  

If the cut is normal, the recipient's mailbox is acceptable to receive mail.

7. Use

The reason why we set up the program to send mail is that if the administrator needs to be prompted in the server management, we can use the way of sending mail to remind.

For example, check disk occupancy at regular intervals every day, and if the occupancy is high, send an email to the administrator telling him to take care of it.

For other purposes, you can write your own scripts according to your needs.

8. mutt parameters

Grammar: mutt [-ES65en][-a] < file > ][-b < address > ][-c < address > ][-f < Mail file > ][-F < The configuration file > ][-H < A draft > ][-i < file > ][-m < type > ][-s < The theme > ][Email Address]

Note: mutt is a text-mode email management program that provides a full-screen interface.

Parameters:
-a < file > Attach additional files to your mail.
-b < address > Specify the addressee address for the BCC copy.
-c < address > Specify the address of the recipient of the copy.
-f < Mail file > Specifies the mail file to load.
-F < The configuration file > Specifies the Settings file for the mutt program without reading the default.muttrc file.
-ES121en shows help.
-H < A draft > Send a draft of the specified message.
-i < file > Inserts the specified file into the message body.
-m < type > Specifies the default mail box type.
-n Do not read the program create file (/etc/Muttrc).
After editing a message in mutt and not wanting to send it immediately, you may postpone sending the message.
-R opens mail files as read-only.
-s < The theme > Specify the subject of the message.
-ES148en displays the version information of mutt and the parameters given when this file was originally compiled.
-x simulates the editing mode of mailx.
When the -ES154en and -ES155en parameters 1 are used together, mutt is not started if there are no messages in the mail file.


Related articles: