mailx(mail)配置outlook SMTP方式发送邮件

简介:

0x01,环境介绍:

我们用的是微软的邮箱打算用SMTP方式发送邮件。先登录账户看官方给出SMTP信息。

wKioL1lDesSQNZlyAAIdtuEC8xo124.png


0x02,系统mailx(mail)设置。

通过命令可以看到,mail实际上是mailx的快捷方式。然后在/etc/mail.rc里加入账号等信息。

wKioL1lDVTXyZV7dAAApnYXoJRU961.png

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


相关文章
|
1月前
|
Ruby
|
1月前
|
数据安全/隐私保护 Ruby
|
1月前
|
数据安全/隐私保护 Ruby
|
12天前
|
网络安全 数据安全/隐私保护 Python
Python SMTP发送邮件
Python SMTP发送邮件
|
1月前
|
API 网络安全 数据安全/隐私保护
SMTP邮件邮箱API发送邮件的方法和步骤
使用SMTP邮件邮箱API(如AokSend)发送邮件涉及6个步骤:获取SMTP服务器地址和端口,进行身份验证,构建邮件内容,连接到服务器,发送邮件及处理结果。例如,Gmail的SMTP服务器地址是smtp.gmail.com,端口587。此方法适用于程序化发送邮件,确保安全并支持大规模发信服务。
|
7月前
|
网络安全 数据安全/隐私保护
用smtp发送邮件,语法错误,无法识别命令。 服务器响应为:Authentication is re
用smtp发送邮件,语法错误,无法识别命令。 服务器响应为:Authentication is re
118 0
|
1月前
|
安全 网络安全 API
SMTP和IMAP的配置方法?
SMTP和IMAP是邮件协议,用于发送和接收邮件。配置SMTP需输入服务器地址(如smtp.gmail.com)、端口(587或465)、安全连接类型(SSL/TLS)和身份验证信息。IMAP配置类似,但服务器地址(如imap.gmail.com)和端口通常是993。AokSend提供触发式SMTP/API接口的高触达发信服务。正确配置后,确保邮件安全可靠传输。如有困难,可查阅服务提供商的帮助文档或联系客服。
|
1月前
|
安全 API 网络安全
163邮箱 SMTP应该怎么配置发信使用?
163邮箱 SMTP应该怎么配置发信使用?
|
10月前
|
网络安全 数据安全/隐私保护 Python
|
10月前
|
Python