This code gives me error again and again. I tried many things but i am unable to do please help me.

using (MailMessage mail = new MailMessage())

                {
                    mail.From = new MailAddress("hello@gmail.com");
                    mail.To.Add("hello@gmail.com");
                    mail.Subject = "Hello World";
                    mail.Body = "<h1>Hello</h1>";
                    mail.IsBodyHtml = true;


                    using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587))
                    {
                        smtp.Credentials = new NetworkCredential("hello@gmail.com", "hello");
                        smtp.EnableSsl = true;
                        smtp.Send(mail);
                    }
                }
    WEB.CONFIG
    <system.net>
        <mailSettings>
          <smtp deliveryMethod="Network" from="unknownuser6601@gmail.com">
            <network host="smtp.gmail.com" port="587" userName="unknownuser6601@gmail.com" password="ASADsohaib" />
          </smtp>
        </mailSettings>
      </system.net>

Related posts

Recent Viewed