hi,
I am trying to code for sending an e-mail in asp.net 3.5 .
here I am getting an runtime exception. I tried below given code in the button click event for sending the e-mail.
protected void Button2_Click(object sender, EventArgs e)
{
MailMessage msg = new MailMessage();
msg.To.Add("[email protected]");
msg.From = new MailAddress("[email protected]");
msg.Subject = txtsubject.Text;
msg.Body = bodytxt.Text;
// msg.Attachments.Add(new Attachment(Server.MapPath("info.txt")));
msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
SmtpClient obj = new SmtpClient();
obj.Host = "smtp.gmail.com";
obj.Port = 587;
obj.UseDefaultCredentials = false;
obj.Credentials = new System.Net.NetworkCredential("[email protected]","94757");
obj.EnableSsl = true;
obj.Send(msg);
// Response.Write("Message Send");
}
I am getting the exception as
"check the response property of the exception to determine why request failed"
"check the status property of the exception to determine why request failed".
please solve problem.
Thanks in advance.
Loading

CrishRank #1,486 · 1.1K reputationPosted May 23, 2010, 11:47 PM EDT
try below code for mail sending using goole smtp
MailMessage mailMsg = new MailMessage(); mailMsg.From = new MailAddress(from); mailMsg.To.Add(to); mailMsg.Subject = subject; mailMsg.IsBodyHtml = true; mailMsg.BodyEncoding = Encoding.UTF8; mailMsg.Body = body; mailMsg.Priority = MailPriority.Normal; // Smtp configuration SmtpClient client = new SmtpClient(); client.Credentials = new NetworkCredential("[email protected]", "yourpassword"); client.Port = 587; //or use 465 client.Host = "smtp.gmail.com"; client.EnableSsl = true; object userState = mailMsg; try { //you can also call client.Send(msg) client.SendAsync(mailMsg, userState); } catch (SmtpException) { //Catch errors... }srinath133 reputationPosted May 24, 2010, 1:18 AM EDT
I tried the code as you said, still I am getting exception for the code in the try block.
plz help me..