title: Execute backend email process without making user to wait for it to complete
body: <p>In my <code>MVC</code> application, I am having a functionality of sending message to the respective owners/dealers, by clients. The <code>message model</code> is as below:</p>
  
  <pre><code>public class Messages
  {
     public string MessageFrom { get; set; }
     public string MessageUserEmailID { get; set; }
     public string MessageUserContactNum { get; set; }
     public string Message { get; set; }
     public int UserID { get; set; }//Admin user id
     public string propertyName { get; set; }
  }
  </code></pre>
  
  <p>and below is my <code>Controller</code> method which will be called through <code>AJAX</code> where </p>
  
  <ul>
  <li>I store the message in DB</li>
  <li>Send the admin a notification through email</li>
  <li>return a <code>Json</code> response back to user.</li>
  </ul>
  
  <p><strong>HomeController</strong></p>
  
  <pre><code>[HttpPost]
  [ValidateAntiForgeryToken]
  public ActionResult SendMessage([Bind(Prefix = "messageModel")]Messages model)
  {
       private SendNotification notify = new SendNotification();
       if (ModelState.IsValid)
       {
            using (db)
            {
               tblMessage messageModel = new tblMessage();
               //....
               //....
               //....
               //fill the messageModel with the model values
               db.tblMessages.Add(messageModel);
               db.SaveChanges();
               string toAddress = db.tblUsers.Where(u =&gt; u.UserId == model.UserID).Select(x =&gt; x.UserEmailID).FirstOrDefault();
               if (!string.IsNullOrEmpty(toAddress))
               {
                    notify.NotifyUser(toAddress, model.MessageUserContactNum, model.propertyName, model.Message, model.MessageFrom, model.MessageUserEmailID, "Kemmale Engineers' Notification - You have a message");
               }
               return Json(new { result = true, message = "Message sent! Thank you! We will get back to you soon!" }, JsonRequestBehavior.AllowGet);
           }
      }
      return Json(new { result = false, message = "Server issue! Please try again later" }, JsonRequestBehavior.AllowGet);
  }
  </code></pre>
  
  <p><strong><code>SendNotification</code></strong> class contains <code>NotifyUser</code> method which is as below:</p>
  
  <pre><code>public void NotifyUser(string toAddress, string userPhoneNum, string propertyName, string userMessage, string userName, string userContactEmail, string subject)
  {
      using (MailMessage mail = new MailMessage())
      {
          string Password = WebConfigurationManager.AppSettings["ApplicationEmailPassword"];
          var securePassword = new SecureString();
          Array.ForEach(Password.ToArray(), securePassword.AppendChar);
          securePassword.MakeReadOnly();
          mail.To.Add(toAddress);
          mail.From = new MailAddress(WebConfigurationManager.AppSettings["ApplicationEmailID"]);
          mail.Subject = subject;
          mail.Body = Convert.ToString(ConstructBody(userMessage, propertyName, userPhoneNum, userContactEmail, userName));
          mail.IsBodyHtml = true;
          mail.Priority = MailPriority.High;
          SmtpClient smtp = new SmtpClient();
          smtp.Host = "smtp.gmail.com";
          smtp.Port = 587;
          smtp.UseDefaultCredentials = false;
          smtp.EnableSsl = true;
          smtp.Credentials = new NetworkCredential(Convert.ToString(mail.From), securePassword);
          smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
          smtp.Send(mail);
      }
  }
  </code></pre>
  
  <p>As you can see that the <code>Notify</code> has return type <code>void</code>. Now how can I return <code>Json</code> message to the user without waiting for <code>Notify</code> method to get executed, since it is very obsolete to make user wait for internal process to complete which is irrelevant to the user? I am thinking of <code>Asynchronous Task</code> but not sure how can I implement it here.</p>