I work on the MVC5 website. This website contains a "contact us" form where a user can contact the website.
The problem is that SendMailAsync takes at least 10-13 seconds to complete (without attachments), and while this process is running, the user is stuck and waiting for a response from the server - regardless of whether the message was sent successfully or not.
This is my current ActionResult method:
[HttpPost]
public async Task<ActionResult> Contact(MessageModel Model)
{
await SendMessage(Model);
return View();
}
And this is my method responsible for sending the email:
private async Task SendMessage(MessageModel Model)
{
var Message = new MailMessage();
Message.From = ...;
Message.To.Add(...);
Message.Subject = ...;
Message.IsBodyHtml = true;
SmtpClient Client = new SmtpClient();
Client.UseDefaultCredentials = false;
Client.Credentials = ...;
Client.Port = 587;
Client.Host = "smtp.office365.com";
Client.DeliveryMethod = SmtpDeliveryMethod.Network;
Client.EnableSsl = true;
await Client.SendMailAsync(Message);
}
Are there any faster working alternatives? I could run it like this:
await Task.Factory.StartNew(() => SendMessage(Model));
- "" 13 , , , .