How to send a mail through mvc-3 asp.net using c#?
I have to send a forgot password so how can I do this? My code is below.
Model code..
usi
you can use this...
public void SendEmail(string address, string subject, string message)
{
string email = "-your-id-@gmail.com";
string password = "put-your-GMAIL-password-here";
var loginInfo = new NetworkCredential(email, password);
var msg = new MailMessage();
var smtpClient = new SmtpClient("smtp.gmail.com", 587);
msg.From = new MailAddress(email);
msg.To.Add(new MailAddress(address));
msg.Subject = subject;
msg.Body = message;
msg.IsBodyHtml = true;
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = loginInfo;
smtpClient.Send(msg);
}
i am using this for sending email, in ASP.net MVC3
System.Web.Helpers.WebMail.SmtpServer = smtp_server;
System.Web.Helpers.WebMail.SmtpPort = smtp_port;
System.Web.Helpers.WebMail.EnableSsl = true;
System.Web.Helpers.WebMail.From = "fromaddress";
StringBuilder sb = new StringBuilder();
sb.Append("<table><tr><td>");
sb.Append(msg);
sb.Append("</td></tr></table>");
string body = sb.ToString();
string To = toemail;
System.Web.Helpers.WebMail.Send(To,subject, body);
Have a look at MvcMailer
MvcMailer provides you with an ActionMailer style email sending NuGet Package for ASP.NET MVC 3/4. So, you can produce professional looking emails composed of your MVC master pages and views with ViewBag.