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

后端 未结 6 1518
南旧
南旧 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: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);
    

提交回复
热议问题