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/