Sending email C# Error Invalid HELO name

Asked

Viewed 115 times

0

My doubt is the following, in the system I develop has option to send email direct from the system, for example Nfe email 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);

Only what happens, in most clients works normally but in some I had problem returning this error(Invalid HELO name (See RFC5321 4.1.1.1)).

In some tests I did to try to resolve, if I put this same setting in Outlook 2010 and do that upload test of it solves the problem in the system as well.

I need to find out what outlook changes in windows configuration to free email sending.

Does anyone have any idea???

2 answers

0

Good afternoon, my friend, What I found out regarding this error caused, is that it has to do with SMTP... Because I’ve been researching this RFC and it refers to the Simple Mail Tranfer Protocol (SMTP) Now have to see if really your configuration is correct with that of Outlook...

Source: https://www.rfc-editor.org/info/rfc5617

0

I use in my projects (I use the email for this) and my code is like this, 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);
        }
    }
}

Below is the Email model 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; }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.