无法使用sendgrid将帐户确认邮件集成到asp.net mvc中

时间:2019-04-14 14:34:36

标签: c# asp.net-mvc sendgrid

我正在关注这篇文章:https://docs.microsoft.com/en-us/aspnet/identity/overview/features-api/account-confirmation-and-password-recovery-with-aspnet-identity 但是仍然不能启用使用asp.net MVC发送帐户确认电子邮件。显示

  找不到

类型或名称空间的网站

public class EmailService : IIdentityMessageService
{
        public Task SendAsync(IdentityMessage message)
        {
            return configSendGridasync(message);
        }

        private Task configSendGridasync(IdentityMessage message)
        {
            var myMessage = new SendGridMessage();
            myMessage.AddTo(message.Destination);
            myMessage.From = new MailAddress("xxxx@.com", "ABC");
            myMessage.Subject = message.Subject;
            myMessage.PlainTextContent = message.Body;
            myMessage.HtmlContent = message.Body;

            var credentials = new NetworkCredential(
                       ConfigurationManager.AppSettings["mailAccount"],
                       ConfigurationManager.AppSettings["mailPassword"]
                       );

            // Create a Web transport for sending email.
            var transportWeb = new System.Web(credentials);

            // Send the email.
            if (transportWeb != null)
            {
                return transportWeb.DeliverAsync(myMessage);
            }
            else
            {
                return Task.FromResult(0);
            }
        }
}

0 个答案:

没有答案