Sending email to Asp net - Gmail

Asked

Viewed 902 times

1

Follow the email sending code, The error reported is in accessing with google SMTP.

        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;
    }
  • Which error?

  • 1

    And what’s the mistake, young man?

  • Google’s SMTP is preventing these connections. Enter the settings and trigger the release of external sending.

  • You have a problem sending the email, Where do I release this Andre? on my own account?

  • I’m looking where I saw this. It was in a newly created account.You did not receive any notification in the gmail account indicating that there was an attempt to send by an external agent?

  • I created it almost a year ago, I’m taking Stacktrace’s mistake to command. one minute!!

  • Follow the error: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at

  • 1

    @Dannysouza new google accounts comes with Login for less secure applications disabled (this includes using SMTP with password). Either the user releases this in the account control panel, or rather, make your application direct the user to a XOAUTH authentication, so that he authorizes your application to access the account, and generating the access token to SMTP.

  • 1

    Denny Souza, I did a search and I saw that I already had a person who asked about the same error/ problem that you are having here in the stack and from what I saw it seems that managed to solve the problem, The link is here > http://answall.com/questions/90462/o-server-smtp-requires-a-connected%C3%A3o-secure-or-the-client-n%C3%A3o-has-been-authenticated I hope you can now solve your problem, and don’t forget to classify the answer as solved later. Good Luck.

Show 4 more comments

1 answer

1

Not long ago I created a new Google account in gmail to use an application agent to send messages. On the first email attempt, the configured account received a notification preventing sending that always redirects to this screen:

Tela de aplicativos menos seguros.

The URL of this option is, Less secure apps

The support case that explains this is described HERE

I hope it helps.

  • 1

    This part of the answer is correct. To be complete the answer, just need to explain how to use SMTP as a secure application (which is better than decreasing security).

  • That’s right, I found this link in my email.

  • @Bacco, I think Google gains a lot of power with this option and we’re even safer. But I don’t think SMTP with SSL is any less secure by being sent from an "unknown" application. But it’s a personal opinion.

  • 2

    @Andremesquita security is not in the sense of SSL or not. The concept is that how people use Google for other things, you let the application (or developer) have its password, it implies access to your email, drive, Hangouts and everything else. If it’s really your account, that’s fine. But since google’s password has become multi-service, it’s not always for "the IT guy" to have access to the rest of the stuff, like posting to Google+ or touching Woogle Wallet. Here comes the new authentication model, where the user separately authorizes the applications and their rights.

  • 1

    @Andremesquita I will make a "point against" defending your point of view: I think that Google could very well let you create a separate password for SMTP, for example, thus solving the problem without running away from conventional authentication. But then it does not go against the company’s expansion policy ;)

Browser other questions tagged

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