1
I am trying to send an email asynchronously, without waiting for the return. However when I do not use the await
I get an exception in return for action
.
Code:
public Task MissaoAvaliada(string usuario, string destinatario)
{
_email.From = new MailAddress("[email protected]");
_email.To.Add(destinatario);
_email.Subject = "Email";
_email.Body = string.Format($"Aqui vai o texto");
return _cliente.SendMailAsync(_email);
}
Action:
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Avaliar(RespostaViewModel viewModel)
{
Resposta resposta = Mapper.Map<Resposta>(viewModel);
Task teste;
if (_respostaService.Update(resposta))
{
teste = _emailService.MissaoAvaliada("Leonardo", "meuemail");
return RedirectToAction("Action", "controller");
}
else
return View(viewModel);
}