Avatar ·

Envio de email via Gmail SMTP em .NET: resolvendo o problema de senha e configurações

Olá a todos! Sou novo em C# e estou tentando implementar o envio de emails via Gmail no meu aplicativo. Estou usando o SmtpClient padrão. Escrevi o seguinte código: ```csharp using System.Net; using System.Net.Mail; var fromAddress = new MailAddress("myemail@gmail.com", "My Name"); var toAddress = new MailAddress("recipient@gmail.com", "Recipient"); const string fromPassword = "mypassword123"; const string subject = "Test"; const string body = "Hello from C#!"; var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(fromAddress.Address, fromPassword) }; using (var message = new MailMessage(fromAddress, toAddress) { Subject = subject, Body = body }) { smtp.Send(message); } ``` Mas ao executar, recebo o erro: "5.5.1 Authentication Required" ou "5.7.0 Username and Password not accepted". Eu já