کد HTML:
[HttpGet]
public ActionResult test()
{return View();
}[HttpPost]
public ActionResult test(string Email, string Name, string Message)
{
if (Message != string.Empty && Message != null)
{
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient();
SmtpServer.Credentials = new System.Net.NetworkCredential(("[email protected]" ), ("ghffhgfh"));
SmtpServer.Port = 25;
SmtpServer.Host = "mail.defender20.ir";
mail.From = new MailAddress((Email));
mail.To.Add("[email protected]");
mail.Subject = ("ارسال پیام");System.Net.Mail.AlternateView alternateViewtxt = System.Net.Mail.AlternateView.CreateAlternateViewF romString(Email, null, "text/html");
mail.AlternateViews.Add(alternateViewtxt);
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure | DeliveryNotificationOptions.OnSuccess;SmtpServer.Send(mail);
ViewBag.Message = "پیام شما با موفقیت ارسال خواهد شد به زودی پاسخ گوی شما خواهیم بود";
}
catch (Exception ex)
{
ModelState.Clear();
ViewBag.Message = "خطا: " + ex.Message.ToString();
}}
return View();
}
برچسب:
نویسنده: محمد رضا جوادیان