0

我有以下代码来发送电子邮件,但我收到以下错误:

An asynchronous module or handler completed while an asynchronous operation was still pending

这是控制器中的代码:

   [AllowAnonymous]
    public async Task<ActionResult> GenerateEmailConfirmation(ApplicationUser user)
    {
        string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

        var callbackUrl = Url.Action(
            "ConfirmEmail",
            "Account",
            new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);

        await UserManager.SendEmailAsync(
            user.Id,
            "Some subject",
            "This the message...<a href=\"" + callbackUrl + "\">here</a>");

        return View("CheckEmail");
    }

这是 identityconfig 中的代码:

    public class EmailService : IIdentityMessageService
    {
        public Task SendAsync(IdentityMessage message)
        {

           var smtpClient = new SmtpClient
           {
                DeliveryMethod = SmtpDeliveryMethod.Network,
                Host = "smtp.gmail.com", 
                Port = 587, 
                EnableSsl = true,  
                UseDefaultCredentials = false, 
                Credentials = new NetworkCredential("jxxx@gmail.com", "xxx")
          };

          var mailMessage = new MailMessage("jxxx@gmail.com", message.Destination)
          {
            Subject = message.Subject,
            Body = message.Body,
            IsBodyHtml = true
          };

         return smtpClient.SendMailAsync(mailMessage);
      }
   }

是什么导致了这个错误?注意应用程序正在防火墙之间运行?

4

0 回答 0