0x01,环境介绍:
我们用的是微软的邮箱打算用SMTP方式发送邮件。先登录账户看官方给出SMTP信息。
0x02,系统mailx(mail)设置。
通过命令可以看到,mail实际上是mailx的快捷方式。然后在/etc/mail.rc里加入账号等信息。
SMTP加密方式是:STARTTLS
1
2
3
4
5
6
7
8
|
set
from=Zabbix使用的发送邮件地址
set
smtp=smtp.office365.com
set
smtp-auth-user=Zabbix使用的发送邮件地址
set
smtp-auth-password=密码
set
smtp-auth=login
set
smtp-use-starttls
set
ssl-verify=ignore
set
nss-config-
dir
=
/etc/pki/nssdb/
|
0x03,创建存放证书的目录
1
|
# mkdir -p /etc/pki/nssdb/
|
0x04,测试mail命令
1
|
echo
"Zabbix test"
| mailx -
v
-s
"test"
wutou@wutou.com
|
Zabbix test 要发送的邮件内容,多行内容要写""里。
test 发送邮件的标题。
wutou@wutou.com 是对方接收邮件的账号。
0x05,测试执行结果,显示如下说明成功。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
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:<wutou@wutou.net>
250 2.1.0 Sender OK
>>> RCPT TO:<wutou@wutou.net>
250 2.1.5 Recipient OK
>>> DATA
354 Start mail input; end with <CRLF>.<CRLF>
>>> .
250 2.6.0 <59434d32.Lx4d3eMhjzYuCHGO%wutou@wutou.net> [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,邮件错误,邮件没有发送成功说明,是认证方式没有设置对。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
[root@appdev zabbix-303]
# echo hello | mailx -v -s "test" wutou@wutou.net
Resolving 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/
本文转自 piazini 51CTO博客,原文链接:http://blog.51cto.com/wutou/1939117