开发者

Troubleshooting "Mailbox unavailable. The server response was: Access denied - Invalid HELO name" when sending email with SmtpClient

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 = "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);

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?


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 = "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);


Have you tried setting your auth credentials in the 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>

and your code behind

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);


Try this:

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);


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.


This can happen if you don't set EnableSsl.

client.EnableSsl = true;


If you have a webmail client available and you see a cPanel logo it could be a setting there as well.

Troubleshooting "Mailbox unavailable. The server response was: Access denied - Invalid HELO name" when sending email with SmtpClient

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜