Every time I write a script under Linux has the ability to send mail, but the configuration under Linux always forget, so this time wrote a small script, record, next time you want to configure the script to run the line. QQ mailbox is used here.
Test environment: CentOS 6.5 x86_64
The script reads as follows:
#!/bin/bash. /etc/init.d/functionsif [ $# -ne 0 ];then echo "usage: sh ' basename $0 '" exit 1 fifrommail= "[email protected] ' smtp_host= ' smtp.qq.com ' smtp_auth_user= ' [email protected] ' smpt_auth_password= ' Mdkuasfhnjbrbhdj ' certs_dir=/root/.certsmail_conf=/etc/mail.rccontent= ' cat $mail _conf |grep ' Smtp-auth-user "if [ " x$content " != " x " ];then action "' $mail _conf ' file already configured" /bin/true exit 1ficat >> $mail _ conf <<eof set from= $frommailset smtp= $smtp _hostset smtp-auth-user= $smtp _auth_ userset smtp-auth-password= $smpt _auth_passwordset smtp-auth=loginset smtp-use-starttlsset ssl-verify=ignoreset nss-config-dir= $certs _direof[ $? -eq 0 ] && action "Configuring $mail_conf Files" &Nbsp;/bin/true [ ! -d $certs _dir ] && mkdir -p $certs _ direcho -n | openssl s_client -connect $SMTP _host:465 | sed -ne '/-begin certificate-/,/-end certificate-/p ' > $certs _dir/qq.crtcertutil -a -n "Geotrust ssl ca" -t "C," -d $certs _dir -i $certs _dir/ qq.crtcertutil -a -n "Geotrust global ca" -t "C,," -d $certs _dir -i $certs _dir/qq.crtcertutil -l -d $certs _dir[ $? -eq 0 ] && action "Generate certificate" /bin/true
Under root user execution:
SH auto_mail_configure.sh
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/8B/2B/wKioL1hGb2PSz5fPAABrjtSQBow777.png-wh_500x0-wm_3 -wmp_4-s_1649197434.png "title=" 1.png "alt=" Wkiol1hgb2psz5fpaabrjtsqbow777.png-wh_50 "/>
Execution complete
Next, execute the following command to test:
echo Hello Word | Mailx-v-S "title" [Email protected]
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/8B/2B/wKioL1hGb9GgFR7CAADbxQeu7_U024.png-wh_500x0-wm_3 -wmp_4-s_3757102619.png "title=" 2.png "alt=" Wkiol1hgb9ggfr7caadbxqeu7_u024.png-wh_50 "/>
See if you have received an email:
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M02/8B/2F/wKiom1hGcDbgrWAWAAE8XplqvXg043.png-wh_500x0-wm_3 -wmp_4-s_2027472456.png "title=" 3.png "alt=" Wkiom1hgcdbgrwawaae8xplqvxg043.png-wh_50 "/>
This article is from the "Xu Mingjiang blog" blog, make sure to keep this source http://dadaloveyou.blog.51cto.com/703960/1880022
Shell Script Auto-Configure send QQ mail