Avatar ·

Envío de email a través de Gmail SMTP en .NET: solución al problema de contraseña y configuración

¡Hola a todos! Soy nuevo en C# y estoy intentando implementar el envío de correos a través de Gmail en mi aplicación. Estoy usando el SmtpClient estándar. Escribí este 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); } ``` Pero al ejecutarlo recibo el error: "5.5.1 Authentication Required" o "5.7.0 Username and Password not accepted". Yo