1. Install and msmtp muttr
yum install -y mutt msmtp
2. Modify Muttr profile
vim /etc/Muttrc
Search these lines and then manually change the following configuration
set charset="utf-8"
set from="自己申请个邮箱@163.com"
set sendmail="/usr/bin/msmtp" #设置发信程序为msmtp set use_from=yes set realname="自己的名字" set editor="vim"
Use sed quickly replaced by the following:
sed -i 's/# set charset=""/set charset="utf-8"/' /etc/Muttrc
sed -i 's/# set from=""/set from="自己的邮箱"/' /etc/Muttrc
#下面这行注意替换的时候有`/`需要前面加上转义字符`\`,不然会出错
sed -i 's/# set sendmail="\/usr\/sbin\/sendmail -oem -oi"/set sendmail="\/usr\/bin\/msmtp"/' /etc/Muttrc
sed -i 's/# set use_from=yes/set use_from=yes/' /etc/Muttrc sed -i 's/# set realname=""/set realname="邮箱的账号"/' /etc/Muttrc sed -i 's/# set editor=""/set editor="vim"/' /etc/Muttrc
3 . New msmtp configuration files msmtprc
and log filesmsmtp.log
touch ~/.msmtp.log
Edit msmtrc, reads as follows:
vi ~/.msmtrc
defaults logfile /var/log/msmtp/msmtp.log # The SMTP server of the provider. account
自己的邮件账号
# SMTP邮件服务器地址 host smtp.163.com # 用来发送邮件Email from 自己的邮件账号@163.com auth login tls off # 用来发送邮件的账号账号 user 自己邮件账号@163.com # 用来发邮件的账号的登陆密码登陆密码,注意163邮箱的密码需要使用单独授权码登录,否则验证失败。 password 你自己的授权密码 # Set a default account account default: 自己的账号
4. Configure permissions for 600 msmtprc
chmod 600 /etc/msmtprc
5. Test e-mail and use mutt
echo "邮件测试" | mutt -s "邮件主题" [email protected]
语 法:
mutt [-hnpRvxz][-a<文件>][-b<地址>][-c<地址>][-f<邮件文 件>][-F<配置文件>][-H<邮件草稿>][-i<文件>][-m<类型>] [-s<主题>][邮件地址] 参 数: -a <文件> 在邮件中加上附加文件。 -b <地址> 指定密件副本的收信人地址。 -c <地址> 指定副本的收信人地址。 -f <邮件文件> 指定要载入的邮件文件。 -F <配置文件> 指定mutt程序的设置文件,而不读取预设的.muttrc文件。 -h 显示帮助。 -H <邮件草稿> 将指定的邮件草稿送出。 -i <文件> 将指定文件插入邮件内文中。 -m <类型> 指定预设的邮件信箱类型。 -n 不要去读取程序培植文件(/etc/Muttrc)。 -p 在mutt中编辑完邮件后,而不想将邮件立即送出,可将该邮件暂缓寄出。 -R 以只读的方式开启邮件文件。 -s <主题> 指定邮件的主题。 -v 显示mutt的版本信息以及当初编译此文件时所给予的参数。 -x 模拟mailx的编辑方式。 -z 与-f参数一并使用时,若邮件文件中没有邮件即不启动mutt。
6. Here I used a piece of code to back up their own websites to illustrate an example
mutt [email protected] -s "itdhz数据备份" -a /home/backup/itdhz.sql </root/readme.txt
echo "test" | mutt [email protected] -s "itdhz数据备份" -a /home/backup/itdhz.sql
This code indicates, send mail to [email protected] this mailbox, message subject is "itdhz data backup" in /root/readme.txt message content, the e-mail contains an attachment /home/backup/itdhz.sql. To send multiple attachments, -a parameters need to add before each attachment.
7. Error Monitoring
tail -f ~/.msmtp.log