在使用SmtpClient发送电子邮件时,“邮箱不可用。服务器响应是:拒绝访问 - 无效的HELO名称”进行故障排除

时间:2010-07-01 05:13:32

标签: c# smtpclient

我一直在尝试通过C#发送电子邮件。我已经搜索了各种各样的例子,并从每个人和最有可能使用的标准代码中获取了一些点点滴滴。

string to = "receiver@domain.com";
string from = "sender@domain.com";
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("test@domain.com", "password");
client.Send(message);

但是,我一直收到错误说明

  

System.Net.Mail.SmtpException:邮箱   不可用。服务器响应是:   拒绝访问 - 无效的HELO名称(请参阅   RFC2821 4.1.1.1)

那么,我现在该怎么办? SmtpClient应该是特殊的,只适用于特定的SMTP服务器吗?

7 个答案:

答案 0 :(得分:7)

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

修改

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

string to = "receiver@domain.com";

//It seems, your mail server demands to use the same email-id in SENDER as with which you're authenticating. 
//string from = "sender@domain.com";
string from = "test@domain.com";

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("test@domain.com", "password");
client.Send(message);

答案 1 :(得分:3)

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

  <system.net>
    <mailSettings>
      <smtp from="test@foo.com">
        <network host="smtpserver1" port="25" userName="username" password="secret" defaultCredentials="true" />
      </smtp>
    </mailSettings>
  </system.net>

以及您的代码

MailMessage message = new MailMessage();
message.From = new MailAddress("sender@foo.bar.com");
message.To.Add(new MailAddress("recipient1@foo.bar.com"));
message.To.Add(new MailAddress("recipient2@foo.bar.com"));
message.To.Add(new MailAddress("recipient3@foo.bar.com"));
message.CC.Add(new MailAddress("carboncopy@foo.bar.com"));
message.Subject = "This is my subject";
message.Body = "This is the content";
SmtpClient client = new SmtpClient();
client.Send(message);

答案 2 :(得分:2)

试试这个:

string to = "receiver@domain.com";
string from = "sender@domain.com";
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);

答案 3 :(得分:0)

就我而言,这是一个错误的端口。主机提供的配置不兼容SSL(465)和SSL(25)。 我使用MS Outlook“破解”配置,然后复制到我的应用程序。这是587 SSL。

答案 4 :(得分:0)

许多人的佩莱尔的环境。.

使用ASP.NET通过SMTP验证发送电子邮件

使用ASP.NET发送具有smtp身份验证的电子邮件 以下代码演示了如何使用ASP.NET发送具有SMTP身份验证的电子邮件:

   //create the mail message

    MailMessage mail = new MailMessage();

    //set the addresses
    mail.From = new MailAddress("postmaster@yourdomain.com"); //IMPORTANT: This must be same as your smtp authentication address.
    mail.To.Add("postmaster@yourdomain.com");

    //set the content
    mail.Subject = "This is an email";
    mail.Body = "This is from system.net.mail using C sharp with smtp authentication.";
    //send the message
     SmtpClient smtp = new SmtpClient("mail.yourdomain.com");

    //IMPORANT:  Your smtp login email MUST be same as your FROM address.
     NetworkCredential Credentials = new NetworkCredential("postmaster@yourdomain.com", "password");
     smtp.Credentials = Credentials;
     smtp.Send(mail);
     lblMessage.Text = "Mail Sent";

注意:请注意,您不能使用System.Net.Mail.SmtpClient发送包含隐式SSL的电子邮件。

答案 5 :(得分:0)

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

client.EnableSsl = true;

答案 6 :(得分:0)

如果您有可用的Webmail客户端,并且看到了cPanel徽标,也可以在其中进行设置。

enter image description here

我们遇到了例外情况,并要求我们的托管公司加入:

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

,然后将Require RFC-compliant HELO设置设为Off

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

在端口587上提交邮件需要SMTP AUTH

来源:

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