Contact us section
I am having problems with my asp.net application i can run the program with no errors when i fill in the boxes on the contact us section i then get a error saying.
SMTPException was unhanded by user code
Here is my code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class contactUs : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void submitform(object sender, EventArgs e)
{
MailMessage email = new MailMessage()
{
Subject = "Email From CraigavonAquatics Contact Us Section",
Body = commentBox.Text,
IsBodyHtml = false,
From = new MailAddress(emailBox.Text, nameBox.Text)
};
email.To.Add(new MailAddress("craigavonaquatics@gmail.com", "Philip Harrison"));
SmtpClient server = new SmtpClient();
server.Send(email);
msgSuccess.Visible = true;
}
You are not specifying any smtp server to use!
Wrap your code in a try catch block. Then, check any inner exceptions.
For example:
try{
...
...
}
catch( Exception ex )
{
Exeception e = ex;
while( e != null ){
Response.Write (e.ToString());
Response.Write("<HR>");
e = e.InnerException;
}
}
}
Many hosting companies do not allow out bound emails that originate from a domain that is not yours. So emails sent from your page at x.com must be from someone like y@x.com.
Add a try catch in there to gather more info.
Bob
Here is a similar discussion: Issue sending mail message from ASP.NET MVC application hosted on GoDaddy
精彩评论