I'm trying to send an email asynchronously, without having to wait for the return. But when I do not use await
I get an exception on return to action
.
Code:
publicTaskMissaoAvaliada(stringusuario,stringdestinatario){_email.From=newMailAddress("[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);
}