疑难解答“邮箱不可用。”服务器响应是:访问被拒绝 - HELO 名称无效”使用 SmtpClient 发送电子邮件时

发布于 2024-09-07 22:52:06 字数 1009 浏览 9 评论 0原文

我一直在尝试用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

自此以后,行同陌路 2024-09-14 22:52:06

看来您的用户名/密码对未通过 SMTP 服务器成功验证

编辑

我想,我发现这里出了什么问题。我已在下面更正了您的版本。

string to = "[email protected]";

//It seems, your mail server demands to use the same email-id in SENDER as with which you're authenticating. 
//string from = "[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.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("[email protected]", "password");
client.Send(message);

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.

string to = "[email protected]";

//It seems, your mail server demands to use the same email-id in SENDER as with which you're authenticating. 
//string from = "[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.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("[email protected]", "password");
client.Send(message);
°如果伤别离去 2024-09-14 22:52:06

您是否尝试过在 web.Config 中设置身份验证凭据?

  <system.net>
    <mailSettings>
      <smtp from="[email protected]">
        <network host="smtpserver1" port="25" userName="username" password="secret" defaultCredentials="true" />
      </smtp>
    </mailSettings>
  </system.net>

和你后面的代码

MailMessage message = new MailMessage();
message.From = new MailAddress("[email protected]");
message.To.Add(new MailAddress("[email protected]"));
message.To.Add(new MailAddress("[email protected]"));
message.To.Add(new MailAddress("[email protected]"));
message.CC.Add(new MailAddress("[email protected]"));
message.Subject = "This is my subject";
message.Body = "This is the content";
SmtpClient client = new SmtpClient();
client.Send(message);

Have you tried setting your auth credentials in the web.Config?

  <system.net>
    <mailSettings>
      <smtp from="[email protected]">
        <network host="smtpserver1" port="25" userName="username" password="secret" defaultCredentials="true" />
      </smtp>
    </mailSettings>
  </system.net>

and your code behind

MailMessage message = new MailMessage();
message.From = new MailAddress("[email protected]");
message.To.Add(new MailAddress("[email protected]"));
message.To.Add(new MailAddress("[email protected]"));
message.To.Add(new MailAddress("[email protected]"));
message.CC.Add(new MailAddress("[email protected]"));
message.Subject = "This is my subject";
message.Body = "This is the content";
SmtpClient client = new SmtpClient();
client.Send(message);
与酒说心事 2024-09-14 22:52:06

试试这个:

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");
// explicitly declare that you will be providing the credentials:
client.UseDefaultCredentials = false;
// drop the @domain stuff from your user name: (The API already knows the domain
// from the construction of the SmtpClient instance
client.Credentials = new NetworkCredential("test", "password");
client.Send(message);

Try this:

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");
// explicitly declare that you will be providing the credentials:
client.UseDefaultCredentials = false;
// drop the @domain stuff from your user name: (The API already knows the domain
// from the construction of the SmtpClient instance
client.Credentials = new NetworkCredential("test", "password");
client.Send(message);
骷髅 2024-09-14 22:52:06

就我而言,这是一个错误的端口。托管提供的配置在 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.

三人与歌 2024-09-14 22:52:06

如果您未设置 EnableSsl,则可能会发生这种情况。

client.EnableSsl = true;

This can happen if you don't set EnableSsl.

client.EnableSsl = true;
×眷恋的温暖 2024-09-14 22:52:06

如果您有可用的网络邮件客户端并且看到 cPanel 徽标,那么它也可能是那里的一个设置。

输入图片这里的描述

我们遇到了异常,并要求我们的托管公司进入:

“Root WHM > 服务配置 >
Exim配置管理器>基本编辑器> ACL 选项”

并将“需要 RFC 兼容的 HELO”设置设置为“关闭”。

在修复下一个错误后,这对我们有用:

在端口 587 上提交消息需要 SMTP AUTH

来源:

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.

enter image description here

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 to Off.

This worked for us after fixing the next error:

SMTP AUTH is required for message submission on port 587

Source:

https://serverfault.com/a/912351/293367

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文