Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

Como resolver o ERRO SMTP 5.7.0 (não é o 5.5.1)

Olá estou recebendo o seguinte erro quando tento enviar o e-mail

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required. Learn more at
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required. Learn more at

Source Error:


Line 39:                     smtpClient.Timeout = 20_000;
Line 40: 
Line 41:                     await smtpClient.SendMailAsync(mensagemDeEmail);
Line 42:                 }
Line 43: 

Tentei soluções que encontrei e simplesmente não consegui resolver. Troquei provedor de email, refiz o código todo, desativei e ativei SSL, configurei meu GMAIL e simplesmente não envia. Quando refiz o código o programa compilou com sucesso fiz o registro e apareceu a mensagem "Bem vindo ao Fórum ByteBank, confirme seu e-mail". Contudo, quando vou para a caixa de entrada do e-mail não há nada lá, e sim(olhei caixa de spam e tudo) o e-mail simplesmente não chega, após essa primeira execução o erro citado acima volta a aparecer... Vasculhei no stackoverflow tentando encontrar uma solução mas todas as que encontrei são essas relacionadas a outro erro. Estou seguindo a risca o código das aulas, unica divergência é a versão do VS que estou usando o 2019. Alguém consegue me ajudar?

2 respostas

Meu código

 public class EmailServico : IIdentityMessageService
    {
        private readonly string EMAIL_ORIGEM = ConfigurationManager.AppSettings["emailServico:email_remetente"];
        private readonly string EMAIL_SENHA = ConfigurationManager.AppSettings["emailServico:email_senha"];

        public async Task SendAsync(IdentityMessage message)
        {
            using (var mensagemDeEmail = new MailMessage())
            {
                mensagemDeEmail.From = new MailAddress(EMAIL_ORIGEM);

                mensagemDeEmail.Subject = message.Subject;
                mensagemDeEmail.To.Add(message.Destination);
                mensagemDeEmail.Body = message.Body;

                // SMTP - Simple Mail Transfer Protocol
                using (var smtpClient = new SmtpClient())
                {
                    smtpClient.UseDefaultCredentials = true; // Sim ja tentei colocar como false, não adiantou.
                    smtpClient.Credentials = new System.Net.NetworkCredential(EMAIL_ORIGEM, EMAIL_SENHA);
                    smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                    smtpClient.Host = "smtp.gmail.com";
                    smtpClient.Port = 587;
                    smtpClient.EnableSsl = true;  // também ja tentei
                    smtpClient.Timeout = 20_000;

                    await smtpClient.SendMailAsync(mensagemDeEmail);
                }
solução!

Consegui resolver!

Era um problema da conta do google q estava utilizando para enviar o e-mail.

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software