Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a asp website with C# ,when i am trying to send a email from my contact form it work in local machine but could not work in hosted page .please help

i am using the following code

What I have tried:

C#
MailMessage mail = new MailMessage();
mail.To.Add("info@domainname.com");
mail.From = new MailAddress("From Email id");
mail.Subject = "Web Enquiry";
string Body = "Name:" + txt_name.Text + "\n";
Body += "Address :" + txt_add.Text + "\n";
Body += "Phone : " + txt_phone.Text + "\n";
Body += "Email : " + txt_email.Text + "\n";
Body += "Course : " + txt_course.Text + "\n";
Body += "Message : \n" + txt_message.Text + "\n";
mail.Body = Body; mail.IsBodyHtml = true;

SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com"";
smtp.Port = 587;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new
System.Net.NetworkCredential("From Email id","Password");
smtp.EnableSsl = true;
smtp.Send(mail);
txt_add.Text = "";
txt_course.Text = "";
txt_email.Text = "";
txt_message.Text = "";
txt_name.Text = "";
txt_phone.Text = "";
txtimgcode.Text = "";
lbl_error.Text = "THANK YOU";
Posted
v2
Comments
Put a try catch and try to catch the exception and log it is file or something. Then only you will be able to know the issue.

1 solution

once try with smtp.EnableSsl=false;
 
Share this answer
 
Comments
Gmail always works with EnableSsl = true.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900