无法使用c#代码连接到Office 365 Smtp Server [英] Cannot connect to office 365 Smtp Server using c# code
问题描述
您好
我正在尝试使用c#代码和SmtpClient类发送电子邮件,但是我收到此错误:" '远程名称无法解析:'smtp.office365.com''。
I'm trying to send an e mail using c# code and the SmtpClient class but I get this error: " 'The remote name could not be resolved: 'smtp.office365.com''.
我看过在我的在线Outlook上设置Smtp设置,并使用与桌面版Outlook中的测试相同的设置。
I have looked up the Smtp settings on my online Outlook and have used the same settings as a test in the desktop version of Outlook.
我很确定我正确使用了SmtpClient类并且有设置:
I'm pretty sure I'm using the SmtpClient class correctly and have set:
- 服务器= smtp.office365.com
- Server = smtp.office365.com
- 端口= 587
- Port = 587
- EnableSsl = true
- EnableSsl = true
- 收件人和来自电子邮件地址是Office 365中的有效用户
-The To and From e mail address is a valid user in Office 365
为什么我的桌面Outlook是否连接到Smtp服务器,但c#代码不能?
Why does my desktop Outlook connect to the Smtp server but the c# code cannot?
谢谢
推荐答案
该错误指向DNS名称解析问题。在您的计算机上,您
从开发,从命令(或PowerShell)运行以下命令:
The error points to a DNS name resolution issue. From your machine you're developing from, run the following from command (or PowerShell):
nslookup< enter>
nslookup <enter>
smtp.office365.com<输入>
smtp.office365.com <enter>
设置q = mx<输入>
set q= mx <enter>
smtp.office365。 com< enter>
smtp.office365.com <enter>
如果DNS正在运行,您应该获得查询的回报。如果没有,它将声明它无法解析名称。
If DNS is working, you should get a return for the queries. If not, it will state that it is unable to resolve the name.
如果您能够从开发机器解析名称,您是否可以共享您用于建立的方法smtp连接?
If you are able to resolve the name from your development machine, can you share the method you're using to establish the smtp connection?
这篇关于无法使用c#代码连接到Office 365 Smtp Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!