Sending email asp net - Gmail [duplicate]

1

Follow the email sending code, The reported error is in google's SMTP access.

        StringBuilder conteudo = new StringBuilder();

    conteudo.Append("O Srº(ª) " + "<b>" + txtNome + "</b>" + " entrou em contato pelo site no dia " + DateTime.Now.ToShortDateString() + " às " + DateTime.Now.ToShortTimeString() + "hrs" + "<br /><br />");
    conteudo.Append("<b>" + "Nome do contato: " + "</b>" + txtNome + "<br />");
    conteudo.Append("<b>" + "Email: " + "</b>" + txtEmail + "<br />");
    conteudo.Append("<b>" + "Telefone: " + "</b>" + txtTelefone + "<br />");
    conteudo.Append("<b>" + "Tipo do serviço: " + "</b>" + ddlServico + "<br />");
    conteudo.Append("<b>" + "Mensagem: " + "</b><br />" + txtMensagem);

    MailMessage msg = new MailMessage(rnConfiguracoes.emailFrom, rnConfiguracoes.emailTo);
    msg.Subject = rnConfiguracoes.nomeDoSite;
    msg.SubjectEncoding = Encoding.Default;
    msg.Body = conteudo.ToString();
    msg.BodyEncoding = Encoding.Default;
    msg.IsBodyHtml = true;
    msg.CC.Add(rnConfiguracoes.emailCC);
    msg.Bcc.Add(rnConfiguracoes.emailBCC);

    var smtpClient = new SmtpClient(rnConfiguracoes.emailSmtp);
    smtpClient.EnableSsl = true;
    smtpClient.Port = 587;

    smtpClient.Credentials = new System.Net.NetworkCredential(rnConfiguracoes.emailLogin, rnConfiguracoes.emailSenha);

    try
    {
        smtpClient.Send(msg);
        return "Mensagem enviada com sucesso. Agradecemos seu contato.";
    }
    catch (Exception ex)
    {
        return ex.StackTrace;
    }
    
asked by anonymous 22.01.2016 / 18:01

1 answer

1

Recently I created a new Google account in gmail to use an application agent to send messages. On the first email attempt, the configured account has been notified of a redemption that always redirects to this screen:

TheURLforthisoptionis Less secure apps

The support case that explains this is described HERE

I hope it helps.

    
22.01.2016 / 18:13