- 使用mailx配置發(fā)送郵件
沒(méi)有安裝的先安裝一下:yum install mailx
由于阿里云的服務(wù)器屏蔽了25端口,所以只能通過(guò)ssl方式發(fā)送郵件(465端口)
修改/etc/mail.rc配置文件,在末尾加入:
set from=xxxx@qq.com
set smtp=smtps://smtp.qq.com:465
set smtp-auth-user=xxxx@qq.com
set smtp-auth-password=郵箱密碼,qq郵箱為授權(quán)登錄碼
set smtp-auth=login
#set smtp-use-starttl //這行加了會(huì)報(bào)錯(cuò),注釋掉
set ssl-verify=ignore
set nss-config-dir=/root/.certs
最后一行為證書(shū)驗(yàn)證,如果證書(shū)錯(cuò)誤會(huì)有報(bào)錯(cuò):Error in certificate: Peer's certificate issuer is not recognized.
但是不影響郵件正常發(fā)送。此問(wèn)題尚未解決。網(wǎng)上說(shuō)配置一下證書(shū),我把網(wǎng)上的操作寫(xiě)成了一個(gè)sh,但是執(zhí)行后仍然報(bào)錯(cuò)。
#!/bin/bash
echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -L -d /root/.certs
配置完成后測(cè)試郵件發(fā)送:
echo "hello world"|mail -v -s "test" xxxxx@qq.com
成功!
- 把日常備份的mysql數(shù)據(jù)庫(kù)sql發(fā)送到郵件中,防止服務(wù)器崩潰后找不到文件
#!bin/bash
cd /data/mysqlbackup
filename="`date +%y%m%d`_yii2_blog.sql"
mysqldump -uroot -p密碼 yii2_blog > $filename
echo "yii2-blog-database backup"|mail -s "yii2-blog-database" -a $filename xxx@qq.com
echo "Your database backup successfully completed"
exit 0
-a 發(fā)送郵件附件
把這個(gè)sh加入到crond服務(wù)中,可以實(shí)現(xiàn)自動(dòng)定期備份數(shù)據(jù)庫(kù)并發(fā)送到自己郵箱中