zhmg23

我们是如此的不同

CentOS6.5下配置用msmtp和mutt发带附件邮件

因近期经常需要定时提取数据,发送给运营同事,提的很烦,所以想改成自动化发送,而且这种方式以前也做过,只是没有整理邮件,今天完成后,顺便把过程整理一下,分享给有需求的各位!


1、安装配置msmtp

下载安装msmtp

cd /usr/local/src

wget  https://ncu.dl.sourceforge.net/project/msmtp/msmtp/1.4.31/msmtp-1.4.31.tar.bz2

tar jxvf msmtp-1.4.31.tar.bz2 

cd msmtp-1.4.31

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

make 

make install 



配置msmtp

cd /usr/local/msmtp/

mkdir -p /usr/local/msmtp/etc

vi /usr/local/msmtp/etc/msmtprc


# Set default values for all following accounts.

defaults

logfile /usr/local/msmtp/msmtp.log 

# The SMTP server of the provider. 

account sendmail

# SMTP邮件服务器地址

host mail.iflytek.com

# 发送的邮件Email

from sendmail@qq.com

auth login

# 邮件服务器登录账号

user sendmail@iflytek.com

# 邮件服务器登陆密码

password mzq1234

# Set a default account

account default: sendmail


把上面的内容添加进去,并保存!


2、安装配置mutt

yum install -y mutt


vim /etc/Muttrc

添加如下内容:

set sendmail='/usr/bin/msmtp'

set use_from=yes


set from="sendmail@qq.com"

set use_from=yes

set envelope_from="yes"

set realname="sendmail"



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


3、测试

echo "各位好 ,附件是xxxx订购数据!" | mutt -a /data/order_txt/2015-10-12.txt -s "上周xxxx订购数据" --   username@qq.com

注: 邮件接入都可以多个,在username@qq.com 后面可以空格写多个

        附件可以通过其他方式从数据库中导出,或者你要发送的其他附件!

评论