SSH安装之msmtp+mutt

2011年3月19日 | 分类: Linux | 标签: , , , , , , , , , ,

原本是集成在见前文的网站数据库自动备份系统里面的,现在独立成篇。

wget http://www.yishanhome.com/wp-content/uploads/2011/03/msmtp.sh;sh msmtp.sh

?Download msmtp.sh
#!/bin/bash
printf "
#This is a Shell-Based tool of install msmtp
# Author: yishan
# Website: http://www.yishanhome.com
"
echo "Command is running, please wait....."
  ret=`rpm -qa|grep mutt|wc -l`
if [ $ret = "0" ] ; then
  echo "install mutt"
    yum install -y mutt
  fi
  ret=`service crond stop|wc -l`
if [ $ret = "0" ] ; then
  echo "install crond"
    yum install -y vixie-cron
  fi
msmtp_url=http://softlayer.dl.sourceforge.net/project/msmtp/msmtp/1.4.23/msmtp-1.4.23.tar.bz2
check_source()
{
  echo "checking $1"
  httpvalue=`wget -nv --spider $1 2>&1|sed q|awk '{print $1}'`
  if [ -z $httpvalue ]; then
    echo "OK!"
  else
    echo "NOT accessible, please check"
    exit
  fi
}
check_source $msmtp_url
echo "Command is ready, press any key to continue....."
read anykey
 
input_MAIL_HOST()
{
  read -p "Please input the Email Server Host Name:" MAIL_HOST
  if [ "$MAIL_HOST" = "" ]; then
  input_MAIL_HOST
  fi
}
input_MAIL_FROM()
{
  read -p "Please input Email From Name:" MAIL_FROM
  if [ "$MAIL_FROM" = "" ]; then
  input_MAIL_FROM
  fi
}
input_MAIL_USER()
{
  read -p "Please input Email User Name:" MAIL_USER
  if [ "$MAIL_USER" = "" ]; then
  input_MAIL_USER
  fi
}
input_MAIL_PWS()
{
  read -p "Please input Email User Password:" MAIL_PWS
  if [ "$MAIL_PWS" = "" ]; then
  input_MAIL_PWS
  fi
}
input_MAIL_SEND()
{
  read -p "Please input test Email Send To:" MAIL_SEND
  if [ "$MAIL_SEND" = "" ]; then
  input_MAIL_SEND
  fi
}
WORK_DIR=/root
mailauth=plain
echo "Please input the Shell-Based Work directory:"
  read -p "(Current directory: $WORK_DIR):" WORK_DIR
  if [ "$WORK_DIR" = "" ]; then
    WORK_DIR=/root
  fi
input_MAIL_HOST
input_MAIL_FROM
input_MAIL_USER
input_MAIL_PWS
input_MAIL_SEND
echo "Please input the Email auth:"
  read -p "(default : $mailauth):" mailauth
  if [ "$mailauth" = "" ]; then
     mailauth=plain
  fi
cd $WORK_DIR
wget $msmtp_url
tar jxvf msmtp-1.4.23.tar.bz2
cd msmtp-1.4.23
./configure --prefix=/usr/local/msmtp
make
make install
mkdir /usr/local/msmtp/etc/
cat > /usr/local/msmtp/etc/msmtprc <<EOF
defaults
tls on
tls_starttls on
tls_certcheck off
logfile /usr/local/msmtp/msmtp.log
account gmail
host $MAIL_HOST
from $MAIL_FROM
auth $mailauth
user $MAIL_USER
password $MAIL_PWS
account default : gmail
EOF
echo "set sendmail=/usr/local/msmtp/bin/msmtp" >>/etc/Muttrc
echo "set use_from=yes" >>/etc/Muttrc
echo "set realname=$MAIL_USER" >>/etc/Muttrc
echo "set editor=vi" >>/etc/Muttrc
chmod 600 /usr/local/msmtp/etc/msmtprc
echo "Successful installation msmtp" | mutt -s "Successful" $MAIL_SEND
目前还没有任何评论.

返回顶部