public ActionResult Index(MailModel model) { using (MailMessage mm = new MailMessage("name@gmail.com", model.To)) { string url = "http://localhost:49458/SendMailer/Login"; string body = "Hello " + model.name + ","; body += "<br /><br />Please click the following link for Login Page"; body += "<br /><a href = '"+url+ "'>Click here to go Login Page</a>"; body += "<br /><br />Thanks"; mm.Body = body; mm.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; NetworkCredential NetworkCred = new NetworkCredential("name@gmail.com", "pwd"); smtp.UseDefaultCredentials = true; smtp.Credentials = NetworkCred; smtp.Port = 587; smtp.Send(mm); } return View(); }
<fieldset> <legend> Send Email </legend> @using (Html.BeginForm()) { @Html.ValidationSummary() <p>To: </p> <p>@Html.TextBoxFor(m => m.To)</p> <p>name: </p> <p>@Html.TextBoxFor(m => m.name)</p> <p>From mail: </p> <p>@Html.TextBoxFor(m => m.Email)</p> <input type="submit" value="Send" /> } </fieldset>
public class MailModel { public string To { get; set; } public string Email { get; set; } public string name { get; set; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)