I'm having a Send Mail function on my site. When debugging on localhost, everything works fine. But when site is published to the web, the SendMail-function returns this error message in the browser everytime i try to send a mail: "Your request timed out. Please retry the request."
Why does it work on localhost, but not on the live published website? What can be the issue?
Here is my code in my mvc-controller:
[HttpPost]
public ActionResult SendMail(HomeContentPage model)
{
const string username = "myMailAdress@gmail.com";
const string password = "mySecretPassword";
var loginInfo = new NetworkCredential(username, password);
var msg = new MailMessage();
var smtpClient = new SmtpClient("smtp.gmail.com", 587)
{
EnableSsl = true,
UseDefaultCredentials = false,
Credentials = loginInfo
};
string message = model.SendMail.SenderName + " have a message for you:<br /><br /><br />" + model.SendMail.Message
+ "<br /><br />Avs. Phone: " + model.SendMail.Phone
+"<br /><br />Avs. Mail: " + model.SendMail.SenderAddress;
var page = RavenSession.Load<ContentPage>(model.Id) as HomeContentPage;
try
{
msg.From = new MailAddress("dwfff@hello.com", "MySite.com");
msg.To.Add(new MailAddress("myMailAdress@gmail.com"));
msg.Subject = "MySite.com";
msg.Body = message;
msg.IsBodyHtml = true;
smtpClient.Send(msg);
page.SendMail.IsSuccess = true;
page.Url = page.Url + "#contact";
return View(page.Template.Name, page);
}
catch (Exception)
{
return View(page.Template.Name, page);
}
}