centos6 利用外部的smpt服務器計劃任務發送郵件

centos可經過修改配置文件以使用外部SMTP服務器,達到不使用sendmail而用外部的smtp服務器發送郵件的目的,shell

操做以下:centos

1、安裝mailx與sendmailbash

#  yum -y install mailx  
# yum -y install sendmail  
# /etc/init.d/sendmail start  
# chkconfig sendmail on  

2、配置發送郵箱的SMPT服務服務器

3、編輯郵件配置文件/etc/mail.rc,添加外部郵件認證信息測試

# vi /etc/mail.rc

set from=xxx@163.com smtp=smtp.163.com
set smtp-auth-user=xx@163.com smtp-auth-password=xxx smtp-auth=login
  • from是發送的郵件地址
  • smtp是發生的外部smtp服務器的地址
  • smtp-auth-user是外部smtp服務器認證的用戶名
  • smtp-auth-password是外部smtp服務器認證的用戶密碼
  • smtp-auth是郵件認證的方式

4、測試郵件發送spa

mail  -s "`date +%F-%T`" xxx@sohu.com </root/messages.txt

5、配置計劃任務的時候須要將郵件發送信息寫入到shell腳本中code

[root@localhost]# cat sendmail.sh 
#!/bin/bash

cat /root/crawler/Crawler_SecInfoLog/"`date +%F`_Crawler_SecInfoLog.txt" | mail -s "爬蟲預警(`date +%F`)" 收信者@163.com
相關文章
相關標籤/搜索