[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(); } }