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
<<EOF
#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}