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

后端 未结 6 1510
南旧
南旧 2021-01-11 18:24

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

相关标签:
6条回答
  • 2021-01-11 18:29

    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.

    0 讨论(0)
  • 2021-01-11 18:39

    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);
    
    0 讨论(0)
  • 2021-01-11 18:41

    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);
    
    0 讨论(0)
  • 2021-01-11 18:42

    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);
    
    0 讨论(0)
  • 2021-01-11 18:44

    This can happen if you don't set EnableSsl.

    client.EnableSsl = true;
    
    0 讨论(0)
  • 2021-01-11 18:54

    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 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 讨论(0)
提交回复
热议问题