linux中,可以使用mail命令往外發送郵件,在使用前,只需要指定如下簡單配置即可,這里演示用 163.com 郵箱發送至 qq.com
編輯 /etc/mail.rc,寫入下方的參數
set from=18211146***@163.com 發送郵件的郵箱
set smtp=smtp.163.com 郵箱域名,使用163郵箱發信,要填寫smtp.163.com,而不是mail.163.com。
set smtp-auth-user=18211146***@163.com #郵箱賬號 set smtp-auth-password=twgdhbtzhy*** #郵箱登錄密碼,或者,授權碼,使用163郵箱需要設置授權碼,這里定義的是授權碼,圖1-1 set smtp-auth=login
[root@Centos7 ~]# tail -10 /etc/mail.rc set from=18211146***@163.com set smtp=smtp.163.com set smtp-auth-user=18211146***@163.com set smtp-auth-password=twgdhbtzhy*** set smtp-auth=login
圖1-1
設置完畢后就可以發件測試了。
郵件標題:Hello World
郵件內容:你好 小戴
收件方:1274378***@qq.com
[root@Centos7 ~]# echo "你好,小戴" |mail -s 'Hello World' 1274378***@qq.com
結果查看。