【发布时间】:2020-09-10 03:39:24
【问题描述】:
所以我按照这里的说明进行操作:https://docs.microsoft.com/en-us/aspnet/core/security/authentication/accconfirm?view=aspnetcore-3.1&tabs=visual-studio
我的应用程序运行正常,并使用我设置的电子邮件服务发送了一封帐户确认电子邮件。
但是,如果我去重设密码,身份服务不会调用电子邮件服务来发送电子邮件指令。我究竟做错了什么?
身份服务如何知道如何使用电子邮件确认帐户但无法使用它重置密码?
为了上下文
startup.cs
// requires
services.AddTransient<IEmailSender, EmailSender>();
services.Configure<AuthMessageSenderOptions>(Configuration);
EmailSender.cs
public class EmailSender:IEmailSender
{
public EmailSender(IOptions<AuthMessageSenderOptions> optionsAccessor)
{
Options = optionsAccessor.Value;
}
public AuthMessageSenderOptions Options { get; } //set only via Secret Manager
public Task SendEmailAsync(string email, string subject, string message)
{
return Execute(Options.SendGridKey, subject, message, email);
}
public Task Execute(string apiKey, string subject, string message, string email)
{
var client = new SendGridClient(apiKey);
var msg = new SendGridMessage()
{
From = new EmailAddress("stackoverflow@blah.com", Options.SendGridUser),
Subject = subject,
PlainTextContent = message,
HtmlContent = message
};
msg.AddTo(new EmailAddress(email));
// Disable click tracking.
// See https://sendgrid.com/docs/User_Guide/Settings/tracking.html
msg.SetClickTracking(false, false);
return client.SendEmailAsync(msg);
}
}
【问题讨论】:
标签: asp.net-core asp.net-core-identity