I have implemented a contact form to a web app but when I try to send the email I get JavaScript runtime errors, http://www.codeproject.com/Tips/371417/Send-Mail-Contact-Form-using-ASP-NET-and-Csharp at line 37
which is an empty line.
Does anyone have an idea as to what is wrong with my implementation or do I have to change some settings to test it on local host?
//calls the SendMail() and resets the textboxes
protected void sendBtn_Click(object sender, EventArgs e)
{
try
{
//here on button click what will done
SendMail();
confirmationLbl.Text = "Your email has been sent to customer support.";
confirmationLbl.Visible = true;
subjectTbx.Text = "";
emailTbx.Text = "";
nameTbx.Text = "";
questionTbx.Text = "";
}
catch (Exception ex) {
confirmationLbl.Text = "Your email has failed to send,please check your connection.";
Console.WriteLine("IOException source: {0}", ex.Message );
}
//line 37 is here, which is blank
}
//method to compose email from textboxes
protected void SendMail()
{
// Gmail Address from where you send the mail
var fromAddress = emailTbx.Text.ToString();
// any address where the email will be sending
var toAddress = "brianDoe@gmail.com";
//Password of your gmail address
const string fromPassword = "Password";
// Passing the values and make a email formate to display
string subject = subjectTbx.Text.ToString();
string body = "From: " + nameTbx.Text + "\n";
body += "Email: " + emailTbx.Text + "\n";
body += "Subject: " + subjectTbx.Text + "\n";
body += "Question: \n" + questionTbx.Text + "\n";
// smtp settings
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.Timeout = 20000;
}
// Passing values to smtp object
smtp.Send(fromAddress, toAddress, subject, body);
}