I wrote the following code in my code file. But it does 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 it shows SMTP Exception handler error. Can anyone help???
try to add DeliveryMethod with the different enumerations, and also credentials before send:
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);
You need to set your credentials before you call the send method.
More information about the error would be helpful though.
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);
Work !!! Thank you