Failed to send email ASP

Asked

Viewed 37 times

0

I have the following code for sending emails, but it is giving error, does not inform of much information just appears "Failed to send email." I’ve changed the door, changed it EnableSsl for true and then to false, the code is as follows::

string nomeRemetente = "Contato";
        string emailRemetente = "[email protected]";
        string assuntoMensagem = assunto;
        MailMessage objEmail = new MailMessage();
        objEmail.From = new System.Net.Mail.MailAddress(nomeRemetente + "<" + emailRemetente + ">");
        foreach (var dest in destinatarios)
        {
            objEmail.To.Add(new MailAddress(dest));
        }
        objEmail.Bcc.Add(new MailAddress("[email protected]"));
        objEmail.Priority = System.Net.Mail.MailPriority.Normal;
        objEmail.IsBodyHtml = true;
        objEmail.Subject = assuntoMensagem;
        objEmail.Body = conteudoMensagem;
        objEmail.From = new MailAddress(emailRemetente);
        objEmail.SubjectEncoding = System.Text.Encoding.GetEncoding("UTF-8");
        objEmail.BodyEncoding = System.Text.Encoding.GetEncoding("UTF-8");
        System.Net.Mail.SmtpClient objSmtp = new System.Net.Mail.SmtpClient();
        objSmtp.Host = "smtp..com.br";
        objSmtp.EnableSsl = true;
        objSmtp.UseDefaultCredentials = false;
        objSmtp.DeliveryMethod = SmtpDeliveryMethod.Network;
        objSmtp.Credentials = new System.Net.NetworkCredential(objEmail.From.ToString(), "senha");
        objSmtp.Port = 587;

        try
        {
            objSmtp.Send(objEmail);
        }
        catch (Exception ex)
        {

        }
        finally
        {
            objEmail.Dispose();
        }

The error occurs in the objSmtp.Send(objEmail);

  • You need more information. You probably have something useful in stack trace or Inner exceptions.

  • @Guilherme-Alves this problem may also be from your network firewall

  • Post the message and Stacktrace of the error that happens.

  • @Kevencarneiro Get general help for this Exception Innerexception: Check the Status Property of the Exception to determine Why the request failed Innerexception: Check the Response Property of the Exception to determine Why the request failed Get general help for the Inner Exception

1 answer

0

Hello, try putting a comma after each email, leaving the last email without the comma at the end.

Ex: Sender1 <"Sender1">, Sender2 <"Sender2">

Browser other questions tagged

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