When I remove the comment “//stmp.timeout” it gives timeout error. What should I do to fix that?
Here is my code:
public ActionResult Index(EmailModel model)
{
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "smtp.gmail.com";
smtp.Port = 180;
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential("sheikh.abm@gmail.com ","somepassword");
//smtp.Timeout = 20000;
}
try
{
smtp.Send("sheikh.abm@gmail.com",model.To, model.Subject, model.Message);
return View("Index");
}
catch (Exception ex)
{
Console.WriteLine(ex); //Should print stacktrace + details of inner exception
if (ex.InnerException != null)
{
Console.WriteLine("InnerException is: {0}", ex.InnerException);
}
}
return View("Index");
In this line
there is a space after
gmail.com. This could prevent the login to gmail. Remove it.Also, I think that the port used to send mail to gmail is 465 for SSL or 587 for TLS/STARTTLS.