Send mail to ASP.NET (SMTP)

I wrote the following code in my code file. But this will not work ... plz help me! :)

protected void Button1_Click(object sender, EventArgs e) { MailMessage msgeme = new MailMessage(" someone@example.com ", " someone@example.com ", "subject", "body"); SmtpClient smtpclient = new SmtpClient("smtp.gmail.com",587); smtpclient.EnableSsl = true; smtpclient.Send(msgeme); smtpclient.Credentials = new NetworkCredential(" someone@example.com ", "password"); } 

I tried both 587 and 465. Bt shows an SMTP exception handler error. Can anyone help?

+4
source share
3 answers

try adding DeliveryMethod with different listings as well as credentials before sending:

 MailMessage msgeme = new MailMessage(" someone@example.com ", " someone@example.com ", "subject", "body"); SmtpClient smtpclient = new SmtpClient("smtp.gmail.com",587); smtpclient.EnableSsl = true; smtpclient.Credentials = new NetworkCredential(" someone@example.com ", "password"); smtpclient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpclient.Send(msgeme); 
+2
source

You need to set credentials before calling the submit method. More detailed error information would be helpful.

+3
source
  MailMessage msgeme = new MailMessage(" someone@example.com ", " someone@example.com ", "subject", "body"); SmtpClient smtpclient = new SmtpClient("smtp.gmail.com",587); smtpclient.EnableSsl = true; smtpclient.Credentials = new NetworkCredential(" someone@example.com ", "password"); smtpclient.DeliveryMethod = SmtpDeliveryMethod.Network; smtpclient.Send(msgeme); 

Job!!! thank you

+1
source

All Articles