Ho implementato un semplice EmailService per Asp.Net Identity 2.0 (tramite l'interfaccia IIdentityMessageService
Asp.Net Identity 2.0 - Come implementare IIdentityMessageService per fare SMTP asincrono usando SmtpClient? .
public class EmailService : IIdentityMessageService
{
public Task SendAsync(IdentityMessage message)
{
// convert IdentityMessage to a MailMessage
var email =
new MailMessage(new MailAddress("[email protected]", "(do not reply)"),
new MailAddress(message.Destination))
{
Subject = message.Subject,
Body = message.Body,
IsBodyHtml = true
};
using (var client = new SmtpClient()) // SmtpClient configuration comes from config file
{
return client.SendMailAsync(email);
}
}
}
Per inviare una e-mail, vado attraverso UserManager:
await _userManager.SendEmailAsync(user.Id, "Confirm your account","Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");
Il problema è che ho un System.Threading.Tasks.TaskCanceledException
quando chiamo SendEmailAsync()
e non è chiaro il perché.
Se invio e-mail in modo sincrono (client.Send(email)
), Eve tutto funziona bene.
Quindi le mie domande sono:
Come posso evitare il TaskCanceledException da farsi espellere? e (supponendo posso superare questo errore),
Come devo fare per comunicare gli errori durante l'invio di email al client (cioè, risposte di tipo "utente inesistente" dal SmtpClient?
Qui è la vostra risposta dettagli https://stackoverflow.com/a/45789677/3835843 – Arif