8
Answers

How to send asynchronous mail in MVC5 ?

mari muthu

mari muthu

8y
297
1
[HttpPost]        public ActionResult Index(MailModel objModelMail, HttpPostedFileBase fileUploader)        {            if (ModelState.IsValid)            {                string from = "[email protected]"; //example:- [email protected]                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,


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 ,

Answers (8)
Next Recommended Forum