0

this is the way i'm sending the email

try
            {
                using (MailMessage mail = new MailMessage())
                {
                    mail.From = new MailAddress("user@domain.com");
                    mail.To.Add("example@gmail.com");
                    mail.Subject = "Hello World";
                    mail.Body = "<h1>Hello</h1>";
                    mail.IsBodyHtml = true;
                    using (System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587))
                    {
                        smtp.Credentials = new System.Net.NetworkCredential("user@domain.com", "password");
                        smtp.EnableSsl = true;
                        smtp.UseDefaultCredentials = false;
                        smtp.Send(mail);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

I did already activate the less secure app in account security setting.

This is the exception error :

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Thameur Saadi
  • 159
  • 1
  • 8
  • [Perhaps this answer](https://stackoverflow.com/a/63894228/3181933) (which seems to cover accounts belonging to the domain, rather than just the specific account which you seem to have already done)? – ProgrammingLlama Oct 14 '20 at 08:16
  • im supposed to send email from `user@domain.com` to `example@gmail.com` – Thameur Saadi Oct 14 '20 at 08:25
  • ...huh? What is your comment in relation to? – ProgrammingLlama Oct 14 '20 at 08:26
  • that's what i understood from your comment xD – Thameur Saadi Oct 14 '20 at 08:29
  • I'll rephrase. In your question you stated: _"I did already activate the less secure app in account security setting."_. This suggests you made the change for `user@domain.com`. The answer I linked to suggests there is another similar setting for `*@domain.com`. As per that answer, please go to https://admin.google.com/ac/security/lsa and see if it is allowed here. – ProgrammingLlama Oct 14 '20 at 08:34
  • "I did already activate the less secure app" That error usually persists when gmail detects unsecure passwords. Consider changing the password and using a more robust/complex one – Cleptus Oct 14 '20 at 08:54
  • 1
    Why not use a service account and go though gmail api why are you using smtp? – Linda Lawton - DaImTo Oct 14 '20 at 12:46
  • Are you sending through Gmail? I can see that you are trying to send to a standard Gmail address but from what it looks like, you're also sending through Gmail? If not, why aren't you using their API? – jdewerth Oct 14 '20 at 20:44

0 Answers0