if [ $(rpm -qa|grep openssl|wc -l) -lt 1]; then
yum -y install openssl openssl-devel
fi
if [ $(rpm -qa|grep sasl|wc -l) -lt 1 ]; then
yum -y install cyrus-sasl-*
fi
if [ -z $(ps -ef|grep sasl|grep -v grep) ]; then
/etc/init.d/saslauthd start
chkconfig saslauthd on
fi
cd ~
wget ftp://ftp.mutt.org/pub/mutt/mutt-1.6.0.tar.gz
tar -zxf mutt-1.6.0.tar.gz
cd mutt-1.6.0
./configure --prefix=/usr/local/mutt --enable-pop --enable-smtp --with-ssl --with-sasl
make && make install
#config
ln -s /usr/local/mutt/bin/mutt /usr/bin/mutt
cp /usr/local/mutt/etc/Muttrc ~/.muttrc
<
#default config
sed -i 's/# set folder="~\/Mail"/set folder="~\/Mail"/' ~/.muttrc
sed -i 's/# set use_envelope_from=no/set use_envelope_from=yes/' ~/.muttrc
#receive user input
read -p "请输入发件人的邮箱帐号(例如[email protected]):" sender_mail
read -p "请输入发件人的邮箱密码:" sender_pass
read -p "请输入发件人名字(例如张三):" sender_name
read -p "请输入邮箱smtp服务器(例如smtp.qq.com:465, 加密协议服务器使用465端口,
smtp.test.com:25,默认协议服务器使用25端口):" smtp_url
#config sender_url
sender_user=$(echo $sender_mail | sed 's/@.*//')
if [ $(echo $smtp_url|cut -d: -f2) -eq 25 ]; then
sender_url="smtp:\/\/${sender_user}@${smtp_url}"
else
sender_url="smtps:\/\/${sender_user}@${smtp_url}"
fi
#echo $sender_url
read -p "请输入测试邮件的接收邮箱地址:" receive_mail
EOF
sender_mail="[email protected]"
sender_name="admin"
sender_pass="321123"
sender_url="smtp.game.com"
sender_url="smtp:\/\/[email protected]"
receive_mail="[email protected]"
#user config
#发件人邮箱
sed -i 's/# set from=""/set from="'"$sender_mail"'"/' ~/.muttrc
#发件人名称
sed -i 's/# set realname=""/set realname="'"$sender_name"'"/' ~/.muttrc
#发件人邮箱密码
sed -i 's/# set smtp_pass=""/set smtp_pass="'"$sender_pass"'"/' ~/.muttrc
#发件人smtp服务器
sed -i 's/# set smtp_url=""/set smtp_url="'"$sender_url"'"/' ~/.muttrc
#测试mutt运行
echo "这里是附件内容" > /tmp/1.txt
echo "这里是测试邮件的正文内容"|/usr/bin/mutt -s "邮件标题" -a /tmp/1.txt -- ${receive_mail}