大网数据广告活动
服务器运维问答

How to send an email with openssl and Microsoft Exchange Online?

· 52CE 我爱测

With Microsoft disabling basic auth in Exchange Online , I set out to add support Modern Authentication in our application. Our app sends basic email alerts. Currently we use SMTP basic auth or open relay for this, but Modern Aut…

问题原文

原帖链接 · JazZeus · CC BY-SA 4.0

With Microsoft disabling basic auth in Exchange Online, I set out to add support Modern Authentication in our application. Our app sends basic email alerts. Currently we use SMTP basic auth or open relay for this, but Modern Auth would be a nice addition.

To fully understand the process, I'd like to go through the entire email process manually. I have a development tenant at Microsoft, in which I have registered our application. I have no issues in acquiring the Oauth token with an email scope. It's the communication with the SMTP server that I can't get through.

As the communication has to be encrypted, I use openssl (instead of telnet). I connect to the server with this command:

openssl s_client -connect smtp.office365.com:587 -crlf -starttls smtp

There is some feedback around SSL negotiation and then the server responds with:

250 SMTPUTF8

At that point I believe I am supposed to use the EHLO command. However, after

EHLO

The response is just (Server changes on every attempt)

' [AM4PR0101CA0056.eurprd01.prod.exchangelabs.com] 

At this point I'm not sure what to do. I believe it may be necessary to insert some domain after the ehlo command (to identify the Microsoft online tenant to connect to?). However, whatever domain I insert, the response is always:

501 5.5.4 Invalid domain name [AM4PR0101CA0056.eurprd01.prod.exchangelabs.com]

Can somebody explain how to initiate communications with a Microsoft Exchange Online tenant via OpenSSL? What do I put after EHLO? Am I connecting to the right address at all? I'm just trying to get to a point where I can issue a AUTH XOAUTH2 command to log in on my tenant.

I've been able to do the complete process om Gmail's smtp server (smtp.gmail.com). On there, it does not matter what you add after the ehlo command, after issuing it you will be greeted and can proceed to login with various AUTH commands.

已采纳解答

原帖链接 · JazZeus · CC BY-SA 4.0

My problem was in the initial command:

openssl s_client -connect smtp.office365.com:587 -crlf -starttls smtp

And specifically the -crlf flag - without it I could enter anything after EHLO and still be greeted by the SMTP server and proceed to AUTH.

The flag seems to do something with line endings which this SMTP server is particularly picky about. So this command works for me:

openssl s_client -connect smtp.office365.com:587 -starttls smtp

I've read other sources that mention adding this flag to resolve issues, for me removing it did the trick. I recommend anyone with the same problem to try both.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-05-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。