E-mail sending C # Error Invalid HELO name

0

My doubts are as follows, in the system I develop you have the option to send direct mail from the system, such as NFe emails and files. I use the following setting to send the email.

MailMessage mensagemEmail = new MailMessage();

mensagemEmail.To.Add("[email protected]");

mensagemEmail.From = new MailAddress("[email protected]", "Nome     Empresa");
mensagemEmail.Subject = Assunto;
mensagemEmail.Body = "<pre>" + Mensagem + "</pre>";

mensagemEmail.IsBodyHtml = true;

SmtpClient client = new SmtpClient();
client.Host = mail.dominio.com.br;
client.Port = 587;
client.EnableSsl = False;

//Email do dominio hostgator
//utilizo essa configuração em todos os clientes
string Usuario = "[email protected]";
string Senha = "Senha";

NetworkCredential cred = new NetworkCredential(Usuario, Senha);
client.Credentials = cred;
client.Send(mensagemEmail);

But what happens, most clients work normally but in some cases I had a problem returning this error.

Invalid HELO name (See RFC5321 4.1.1.1)

In some tests that I did to try to solve, if I put this same configuration in outlook 2010 and make that send test it solves the problem in the system too.

I need to find out what Outlook changes in the windows configuration to release the email.

Does anyone have any ideas?

    
asked by anonymous 20.11.2017 / 17:11

2 answers

0

Good afternoon, my friend, What I discovered about this error caused is that it has to do with SMTP ... I have been researching about this RFC and it is referring to Simple Mail Tranfer Protocol (SMTP) Now you have to see if your configuration is really correct with that of Outlook ...

Source: link

    
20.11.2017 / 20:47
0

I use in my projects (I use email for this) and my code stays that way, adapt to your need and test there:

Check if you need SSL and default Credentials tbm.

public static void Send(Email email)
{
    using (var smtp = new SmtpClient())
    {
        smtp.Host = email.Host;
        smtp.Port = email.Port;
        smtp.EnableSsl = true;
        smtp.UseDefaultCredentials = true;
        smtp.Credentials = new System.Net.NetworkCredential(email.AddressFrom, email.Password);
        using (var mail = new MailMessage())
        {
            mail.From = new MailAddress(email.AddressFrom);
            mail.To.Add(new MailAddress(email.AddressTo));
            mail.Subject = email.Subject;
            mail.Body = email.Message;
            mail.IsBodyHtml = true;
            smtp.Send(mail);
        }
    }
}

Follow the email template below to help you if you want to use this example:

public class Email
{
    public string Host { get; set; }
    public int Port { get; set; }
    public string Password { get; set; }
    public string AddressFrom { get; set; }
    public string Subject { get; set; }
    public string Message { get; set; }
    public string AddressTo { get; set; }
}
    
20.11.2017 / 23:20