mailx(mail)配置outlook SMTP方式發送郵件

  • 2019 年 10 月 5 日
  • 筆記

轉載文章。 因為目前資料庫備份腳本缺少告警機制,告警平台還沒完善,因此臨時用郵箱告警。

outlook郵箱的告警比較噁心,搜了好久終於找到這篇部落格。

0x01,環境介紹:

我們用的是微軟的郵箱打算用SMTP方式發送郵件。先登錄賬戶看官方給出SMTP資訊。

0x02,系統mailx(mail)設置。

通過命令可以看到,mail實際上是mailx的快捷方式。然後在/etc/mail.rc里加入帳號等資訊。

SMTP加密方式是:STARTTLS

set from=Zabbix使用的發送郵件地址set smtp=smtp.office365.comset smtp-auth-user=Zabbix使用的發送郵件地址set smtp-auth-password=密碼set smtp-auth=loginset smtp-use-starttlsset ssl-verify=ignoreset nss-config-dir=/etc/pki/nssdb/

0x03,創建存放證書的目錄

# mkdir -p /etc/pki/nssdb/

0x04,測試mail命令

echo "Zabbix test" | mailx -v -s "test" [email protected]

Zabbix test 要發送的郵件內容,多行內容要寫""里。

test 發送郵件的標題。

[email protected] 是對方接收郵件的帳號。

0x05,測試執行結果,顯示如下說明成功。

Resolving host smtp.office365.com . . . done.  Connecting to 40.97.113.2:smtp . . . connected.  220 DM5PR06CA0069.outlook.office365.com Microsoft ESMTP MAIL Service ready at Fri, 16   Jun 2017 03:16:13 +0000>>> EHLO iconnappdev.us.wutou.net  250-DM5PR06CA0069.outlook.office365.com Hello [204.246.137.148]250-SIZE 157286400  250-PIPELINING  250-DSN  250-ENHANCEDSTATUSCODES  250-STARTTLS  250-8BITMIME  250-BINARYMIME  250 CHUNKING>>> STARTTLS  220 2.0.0 SMTP server ready  Error in certificate: Peer's certificate issuer is not recognized.  Comparing DNS name: "*.clo.footprintdns.com"Comparing DNS name: "*.hotmail.com"Comparing DNS name: "*.internal.outlook.com"Comparing DNS name: "*.live.com"Comparing DNS name: "*.office.com"Comparing DNS name: "*.office365.com"SSL parameters: cipher=AES-256, keysize=256, secretkeysize=256,  issuer=CN=DigiCert Cloud Services CA-1,O=DigiCert Inc,C=US  subject=CN=outlook.com,O=Microsoft Corporation,L=Redmond,ST=Washington,C=US>>> EHLO appdev.us.wutou..net  250-DM5PR06CA0069.outlook.office365.com Hello [204.246.137.148]250-SIZE 157286400  250-PIPELINING  250-DSN  250-ENHANCEDSTATUSCODES  250-AUTH LOGIN XOAUTH2  250-8BITMIME  250-BINARYMIME  250 CHUNKING>>> AUTH LOGIN  334 VXNlcm5hbWU6>>> emFiYml4QGFyaWl4LmNvbQ==334 UGFzc3dvcmQ6>>> WmFyaWl4MTE=235 2.7.0 Authentication successful target host BN6PR11MB0017.namprd11.prod.outlook.com>>> MAIL FROM:<[email protected]>250 2.1.0 Sender OK>>> RCPT TO:<[email protected]>250 2.1.5 Recipient OK>>> DATA  354 Start mail input; end with <CRLF>.<CRLF>>>> .250 2.6.0 <59434d32.Lx4d3eMhjzYuCHGO%[email protected]> [InternalId=4849018077783, Hostn     ame=BN6PR11MB0017.namprd11.prod.outlook.com] 2808 bytes in 0.560, 4.895 KB/sec Queued      mail for delivery>>> QUIT  221 2.0.0 Service closing transmission channel

0x06,郵件錯誤,郵件沒有發送成功說明,是認證方式沒有設置對。

[root@appdev zabbix-303]# echo hello | mailx -v -s "test" [email protected] host smtp.office365.com . . . done.  Connecting to 40.97.134.210:smtp . . . connected.  220 MWHPR15CA0065.outlook.office365.com Microsoft ESMTP MAIL Service ready at Fri, 16      Jun 2017 03:14:01 +0000    250-MWHPR15CA0065.outlook.office365.com Hello [204.246.137.148]250-SIZE 157286400  250-PIPELINING  250-DSN  250-ENHANCEDSTATUSCODES  250-STARTTLS  250-8BITMIME  250-BINARYMIME  250 CHUNKING>>> STARTTLS  220 2.0.0 SMTP server ready  Missing "nss-config-dir" variable."/root/dead.letter" 11/296. . . message not sent.

參考文章:

http://www.mamicode.com/info-detail-1430328.html

http://freman.blog.51cto.com/1309295/1216126/

Tags: