如何在MVC5中发送异步邮件? [英] How to send asynchronous mail in MVC5 ?
本文介绍了如何在MVC5中发送异步邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
[HttpPost]
public ActionResult Index(MailModel objModelMail, HttpPostedFileBase fileUploader)
{
if (ModelState.IsValid)
{
string from = "muthujuna@gmail.com"; //example:- sourabh9303@gmail.com
using (MailMessage mail = new MailMessage(from, objModelMail.To))
{
mail.Subject = objModelMail.Subject;
mail.Body = objModelMail.Body;
if (fileUploader != null)
{
string fileName = Path.GetFileName(fileUploader.FileName);
mail.Attachments.Add(new Attachment(fileUploader.InputStream, fileName));
}
mail.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential networkCredential = new NetworkCredential(from, "XXXX");
smtp.UseDefaultCredentials = true;
smtp.Credentials = networkCredential;
smtp.Port = 587;
ParsingTemplate();
smtp.Send(mail);
ViewBag.Message = "Sent";
return View("Index", objModelMail);
}
}
else
{
return View();
}
}
我的尝试:
hi frnds,
我正在尝试使用Mvc4发送一封带附件的邮件。但它需要花费时间太长时间发送。超过3分钟它的加载终于得到超时错误但文件的小尺寸没有问题。现在我想发送asyncronously电子邮件必须发送...请如果有人知道这帮助我或者分享一些链接怎么做请帮帮我,
What I have tried:
hi frnds,
I am trying to send one mail with Attachment using Mvc4.but it Takes time too long to send.more than 3 minutes its loaded finally am getting Timeout Error but small size of files no issues .now i want to send asyncronously Email has to be send...please if some one know this help me or share some links how to do that please help me ,
推荐答案
你好,
Hangfire,哪个帮助您像工作一样在后台发送邮件。
请尝试以下链接:
使用ASP.NET MVC在后台发送邮件& mdash; Hangfire 1.5文档 [ ^ ]
另外, Quartz Enterprise Scheduler .NET | Quartz.NET文档 [ ^ ]
你也可以使用SendEmailAsync()
c# - .SendMailAsync()在MVC中使用 [ ^ ]
谢谢
Hello,
Hangfire, which helps you send mails on the background like a job.
Try the below link:
Sending Mail in Background with ASP.NET MVC — Hangfire 1.5 documentation[^]
Also, Quartz Enterprise Scheduler .NET | Quartz.NET Documentation[^]
You can also use SendEmailAsync()
c# - .SendMailAsync() use in MVC[^]
Thanks
这篇关于如何在MVC5中发送异步邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文