smtp connection error with C#(authenticated)

Asked

Viewed 1,746 times

1

Below is the Script used when trying to send an error: Failure to an SSPI call. Client and Server cannot communicate because they do not have a common algorithm.

string CorpoEmail = file;
    MailMessage mailMessage = new MailMessage();
    // Endereco que irá aparecer no e-mail do usuário
    mailMessage.From = new MailAddress("[email protected]", "Fale Conosco");
    // Destinatarios do e-mail, para incluir mais de um basta separar por ponto e virgula
    mailMessage.To.Add(destinatario);
    mailMessage.Subject = assunto;
    mailMessage.IsBodyHtml = true;
    // Conteudo do corpo do e-mail
    mailMessage.Body = CorpoEmail.ToString();
    mailMessage.Priority = MailPriority.High;
    //smtp do e-mail que irá enviar
    SmtpClient smtpClient = new SmtpClient();
    smtpClient.EnableSsl = true;
    smtpClient.Host = "smtp.host.com.br";
    smtpClient.Port = 587;


    smtpClient.UseDefaultCredentials = false;
    //credenciais da conta que utilizará para enviar o e-mail
    smtpClient.Credentials = new 
    NetworkCredential("[email protected]", "senha");
    smtpClient.Send(mailMessage);
    return true;
  • The error is not in the code, but in the communication between the server where the application is running and the smtp server. To make sure that you can send an email using any gmail account, for example. As for communication between computers, for some reason the server must be blocking, more information about them will be needed. See: https://technet.microsoft.com/en-us/library/dd197582(v=Ws.10). aspx

  • I was doing some tests here and I made an example with Python using his SMTP class and be able to do the Email Submission will have some configuration I can do in C# to be able to send ?

  • Have you tried to remove Ssl for a test? smtpClient.EnableSsl = false;

  • Yes, I tried there is another error saying that the connection requires starttls, using port 25 can send normally, only I need to send by secure port of Server

  • See if anything of that answer of SO help.

1 answer

2

Apparently you are trying to make a call with SSL/TLS using a non-secure port (587), try to disable the SSL/TLS function, so replace this value:

smtpClient.EnableSsl = true;

For that:

smtpClient.EnableSsl = false;

This should solve your problem, if the error persists, make sure the host is correct and active in "smtpClient.Host".

Browser other questions tagged

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