This is my code try to send mailif you have any idea to solve this help me guys
enter code here
public ActionResult ContactForm(Contact cnt)
{
BlogApplicationEntities db = new BlogApplicationEntities();
if (ModelState.IsValid)
{
try
{
MailMessage msg = new MailMessage();
SmtpClient smtp = new SmtpClient();
msg.To.Add(new MailAddress("send to mail address"));
msg.Subject = "Contact Us";
msg.Body += "\nFirst Name=" + cnt.FirstName;
msg.Body += "Last Name=" + cnt.LastName;
msg.Body += "Email=" + cnt.Email;
msg.From = new MailAddress("mailaddress", "Jhon");
msg.Body += "Comments=" + cnt.Comment;
msg.IsBodyHtml = true;
smtp.Credentials = new System.Net.NetworkCredential("network mail address", "**password**");
smtp.Host = "https://smtp.gmail.com";
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Port = 587;
smtp.Send(msg);
msg.Dispose();
db.Contacts.Add(cnt);
db.SaveChanges();
return View("Success");
}
catch (Exception)
{
return View("Error");
}
}
return View();
}
When the below line is executed:
smtp.Send(msg);
Its throws an error :
'The remote name couldn't be resolved: https://smtp.gmail.com'
What can I do to solve this, can someone help me?