Reputation: 83
This is an extremely simple contact form that just runs the following code on a button click event. The problem is that inside the network this thing works absolutely fine, but when I try outside nothing is happening, but a 500 server error. What is particularly odd is that this was working A-OK a few days ago. I am guessing this is something perhaps happening with the DNS. My question is , how I can stop this from happening and make this form more stable?
string toAddress = "[email protected]";
string fromAddress = "[email protected]";
string mailServer = "mail.mydomain.com";
DateTime now = DateTime.Now;
MailMessage myMailMessage = new MailMessage();
myMailMessage.To.Add(toAddress);
myMailMessage.From = new MailAddress(fromAddress);
myMailMessage.Subject = "Contact Form Submission";
myMailMessage.Body =
"some text" + "\r\n" +
"-------------------------------------------" +
"\r\n" +
"xxx#: " + xxx.Text.ToString() +
"\r\n" + "FirstName: " + FirstName.Text.ToString() +
"\r\n" + "LastName: " + LastName.Text.ToString() +
"\r\n" + "City: " + City.Text.ToString() +
"\r\n" + "ListPrice: " + ListPrice.Text.ToString() +
"\r\n" + "Features: " + Features.Text.ToString() +
"\r\n"
SmtpClient mySmtpClient = new SmtpClient(mailServer);
mySmtpClient.Send(myMailMessage);
Response.Redirect("thankyou.aspx");
Upvotes: 1
Views: 235
Reputation: 66641
The 500 server error is a generic message, you need to read the detailed message on event viewer.
Possible issues here. If you send the email from the server that also hold the mailserver change the mailServer name to localhost
string mailServer = "localhost";
and setup the mail server to accept the mails come from local. If you have the mail server somewhere else then you need to check
and make the code according to that options.
Upvotes: 1