0

I get the exception of

System.Net.Mail.SmtpException

...and when expanded it says

client not authenticated

how to fix?

string to, from, pas, mail;
            to = "****";
            from = "****";
            mail = "Email Content";
            pas = "****";

            MailMessage message = new MailMessage();
            message.To.Add(to);
            message.From = new MailAddress(from);
            message.Body = mail;
            message.Subject = "Email Testing";
            SmtpClient smtp = new SmtpClient("smtp.gmail.com");
            smtp.EnableSsl = true;
            smtp.Port = 587;
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            smtp.Credentials = new NetworkCredential(from, pass);

            try
            {
                smtp.Send(message);
                System.Diagnostics.Debug.WriteLine("Sent");
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }

I already have the import of

using System.Net;
using System.Net.Mail;
MickyD
  • 14,343
  • 6
  • 43
  • 67
cedieasd
  • 13
  • 3
  • In this line `smtp.Credentials = new NetworkCredential(from, pass);` you write `pass`, but password in variable `pas` – Dmitry Aug 10 '21 at 12:04

0 Answers0