疑难解答“邮箱不可用。”服务器响应是:访问被拒绝 - HELO 名称无效”使用 SmtpClient 发送电子邮件时
我一直在尝试用C#发送电子邮件。我在谷歌上搜索了各种示例,并从每个示例和每个人最有可能使用的标准代码中获取了一些片段。
string to = "[email protected]";
string from = "[email protected]";
string subject = "Hello World!";
string body = "Hello Body!";
MailMessage message = new MailMessage(from, to, subject, body);
SmtpClient client = new SmtpClient("smtp.domain.com");
client.Credentials = new NetworkCredential("[email protected]", "password");
client.Send(message);
但是,我不断收到错误消息
System.Net.Mail.SmtpException:邮箱 不可用。服务器响应是: 访问被拒绝 - HELO 名称无效(请参阅 RFC2821 4.1.1.1)
那么,我现在该怎么办? SmtpClient 应该是特殊的并且只能在特定的 SMTP 服务器上工作吗?
I have been trying to send an email by C#. I have Googled for various examples and have taken bits and pieces from each and from the standard code which everyone would most probably be using.
string to = "[email protected]";
string from = "[email protected]";
string subject = "Hello World!";
string body = "Hello Body!";
MailMessage message = new MailMessage(from, to, subject, body);
SmtpClient client = new SmtpClient("smtp.domain.com");
client.Credentials = new NetworkCredential("[email protected]", "password");
client.Send(message);
However, I keep getting an error stating
System.Net.Mail.SmtpException: Mailbox
unavailable. The server response was:
Access denied - Invalid HELO name (See
RFC2821 4.1.1.1)
So, what do I do now? Is SmtpClient supposed to be special and only work on specific SMTP servers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
看来您的用户名/密码对未通过 SMTP 服务器成功验证。
编辑
我想,我发现这里出了什么问题。我已在下面更正了您的版本。
It seems your username/password pair is not authenticating successfully with your SMTP server.
EDIT
I think, I found what's wrong here. I have corrected your version below.
您是否尝试过在 web.Config 中设置身份验证凭据?
和你后面的代码
Have you tried setting your auth credentials in the web.Config?
and your code behind
试试这个:
Try this:
就我而言,这是一个错误的端口。托管提供的配置在 SSL (465) 和无 SSL (25) 上均不起作用。
我使用 MS Outlook 来“破解”配置,然后复制到我的应用程序中。这是 587 SSL。
In my case, it was a wrong port. The configuration provided by the hosting didn't worked both SSL (465) and no SSL (25).
I used MS Outlook to "crack" the configuration, and then copied to my application. It was 587 SSL.
如果您未设置 EnableSsl,则可能会发生这种情况。
This can happen if you don't set EnableSsl.
如果您有可用的网络邮件客户端并且看到 cPanel 徽标,那么它也可能是那里的一个设置。
我们遇到了异常,并要求我们的托管公司进入:
“Root WHM > 服务配置 >
Exim配置管理器>基本编辑器> ACL 选项”
并将“需要 RFC 兼容的 HELO”设置设置为“关闭”。
在修复下一个错误后,这对我们有用:
来源:
https://serverfault.com/a/912351/293367
If you have a webmail client available and you see a cPanel logo it could be a setting there as well.
We got the exception and asked our hosting company to go into:
"Root WHM > Service Configuration >
Exim Configuration Manager > Basic Editor > ACL Options"
and set the
Require RFC-compliant HELO
setting toOff
.This worked for us after fixing the next error:
Source:
https://serverfault.com/a/912351/293367