Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i want to send a mail using mvc3 and razor.
i already write a code but it was not running.

[HttpPost]
public ViewResult ContactUs(MailModel _objModelMail)
{
if (ModelState.IsValid)
{
MailMessage mail = new MailMessage();
mail.To.Add("abcd@gmail.com");
mail.From = new MailAddress(_objModelMail.From);
mail.Subject = _objModelMail.Subject;
string Body = _objModelMail.Body;
mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "64.31.2.235";
//smtp.Port = 587;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential
("cbcd@phoneafriendcard.com", "@@@@@@");// Enter seders User name and password
smtp.EnableSsl = true;
smtp.Send(mail);
return View("ContactUs", _objModelMail);
}
else
{
return View();
}

}
Posted
Updated 25-Aug-15 20:16pm
v2

1 solution

Try using a DNS name instead of IP, read the following : Send Email from Yahoo!, GMail, Hotmail (C#)[^]
 
Share this answer
 
Comments
aiswarjya 26-Aug-15 2:40am    
button click event was not fire in mvc3 razor while sending mail.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900