如何为ASP.NET Identity UserManager.SendEmailAsync配置发件人电子邮件凭据? [英] How to configure sender email credentials for ASP.NET Identity UserManager.SendEmailAsync?

查看:139
本文介绍了如何为ASP.NET Identity UserManager.SendEmailAsync配置发件人电子邮件凭据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Asp.net Web应用程序.在我的应用程序中,我正在设置用户电子邮件确认和密码重置功能.我正在使用内置在身份系统中的Asp.net.可以通过此链接启用这些功能- https://www.asp.net/identity/overview/features-api/account-confirmation-and-password-recovery-with-aspnet-ident .

I am developing an Asp.net web application. In my application, I am setting up user email confirm and password reset feature. i am using Asp.net built in Identity system. Those features can be enabled following this link - https://www.asp.net/identity/overview/features-api/account-confirmation-and-password-recovery-with-aspnet-identity according to mention in Visual Studio.

但是要遵循它,此链接已断开- https://azure.microsoft.com/zh-CN/gallery/store/sendgrid/sendgrid-azure/.但是没关系,我只想知道asp.net身份系统中的一件事.那是发送电子邮件.根据Visual Studio中的注释行,我可以像下面这样发送重置密码电子邮件.

But to follow it, this link is broken - https://azure.microsoft.com/en-us/gallery/store/sendgrid/sendgrid-azure/. But it is ok, I want to know only one thing in asp.net identity system. That is sending email. According to the commented lines in Visual Studio, I can send reset password email like this below.

await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>");

该行简单易读.但是问题是我可以在哪里配置发件人电子邮件凭据?它用来发送电子邮件的设置是什么?我该如何更改发件人电子邮件?我也无法跟踪该链接,因为Azure链接已损坏.在哪里可以设置和更改这些设置?

That line is simple and readable. But the problem is where can I configure sender email credentials? What settings it uses to send email? How can I change the sender email please? I cannot follow the link as well because Azure link is broken. Where can I set and change those settings?

我尝试在web.config中添加此设置

I tried add this settings in web.config

<system.net>
    <mailSettings>
      <smtp from="testing@gmai.com">
        <network host="smtp.gmail.com" password="testing" port="587" userName="testing"  enableSsl="true"/>
      </smtp>
    </mailSettings>
  </system.net>

但是现在发送电子邮件.

But now sending email.

推荐答案

最后我找到了解决方案.

Finally I found the solution.

我在web.config中像这样添加了电子邮件设置

I added there email settings in web.config like this

<system.net>
    <mailSettings>
      <smtp from="testing@gmai.com">
        <network host="smtp.gmail.com" password="testing" port="587" userName="testing"  enableSsl="true"/>
      </smtp>
    </mailSettings>
  </system.net>

然后我更新了

public class EmailService : IIdentityMessageService
    {
        public Task SendAsync(IdentityMessage message)
        {
            // Plug in your email service here to send an email.

            return Task.FromResult(0);
        }
    }

在App_Start文件夹中的IdentityConfig.cs中

in the IdentityConfig.cs in the App_Start folder to this

public class EmailService : IIdentityMessageService
    {
        public Task SendAsync(IdentityMessage message)
        {
            // Plug in your email service here to send an email.
            SmtpClient client = new SmtpClient();
            return client.SendMailAsync("email from web.config here",
                                        message.Destination,
                                        message.Subject,
                                        message.Body);

        }
    }

当我发送电子邮件时,它会自动使用web.config中的设置.

When I send email, it auto use the settings from the web.config.

这篇关于如何为ASP.NET Identity UserManager.SendEmailAsync配置发件人电子邮件凭据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆