Reputation: 65
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("[email protected]", "[email protected]", "subject", "body");
SmtpClient smtpclient = new SmtpClient("smtp.gmail.com",587);
smtpclient.EnableSsl = true;
smtpclient.Send(msgeme);
smtpclient.Credentials = new NetworkCredential("[email protected]", "password");
}
I tried both 587 and 465. Bt it shows SMTP Exception handler error. Can anyone help???
Upvotes: 4
Views: 4452
Reputation: 11
MailMessage msgeme = new MailMessage("[email protected]", "[email protected]", "subject", "body");
SmtpClient smtpclient = new SmtpClient("smtp.gmail.com",587);
smtpclient.EnableSsl = true;
smtpclient.Credentials = new NetworkCredential("[email protected]", "password");
smtpclient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpclient.Send(msgeme);
Work !!! Thank you
Upvotes: 1
Reputation: 5545
try to add DeliveryMethod with the different enumerations, and also credentials before send:
MailMessage msgeme = new MailMessage("[email protected]", "[email protected]", "subject", "body");
SmtpClient smtpclient = new SmtpClient("smtp.gmail.com",587);
smtpclient.EnableSsl = true;
smtpclient.Credentials = new NetworkCredential("[email protected]", "password");
smtpclient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpclient.Send(msgeme);
Upvotes: 2
Reputation: 28148
You need to set your credentials before you call the send method. More information about the error would be helpful though.
Upvotes: 3