电子邮件重置密码不起作用,但帐户确认有效.NetCore
Email reset password not working, however account confirmation works .NetCore
我的应用程序运行正常,并使用我设置的电子邮件服务发送了一封帐户确认电子邮件。
但是,如果我去重设密码,身份服务不会调用电子邮件服务来发送电子邮件说明。我究竟做错了什么?
身份服务如何知道如何使用电子邮件来确认帐户但不能使用它来重置密码?
对于上下文
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("Whosebug@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);
}
}
我们 运行 遇到了同样的问题,发现在发送注册电子邮件时,没有发送密码重置电子邮件。在我们的例子中,这是因为 AspNetUsers
table:
的两个问题
- 我们没有完成电子邮件确认步骤,它将数据库中的
EmailConfirmed
布尔值设置为 True
,并且
- 我们从 ASP.NET Core 的早期版本迁移了数据,其中两个电子邮件字段
Email
和 NormalizedEmail
未设置并保留 null
.
一旦我们填充了缺失的电子邮件字段,并且 运行 确认步骤——或手动将标志更改为 True
——密码重置电子邮件开始工作。
我的应用程序运行正常,并使用我设置的电子邮件服务发送了一封帐户确认电子邮件。
但是,如果我去重设密码,身份服务不会调用电子邮件服务来发送电子邮件说明。我究竟做错了什么?
身份服务如何知道如何使用电子邮件来确认帐户但不能使用它来重置密码?
对于上下文
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("Whosebug@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);
}
}
我们 运行 遇到了同样的问题,发现在发送注册电子邮件时,没有发送密码重置电子邮件。在我们的例子中,这是因为 AspNetUsers
table:
- 我们没有完成电子邮件确认步骤,它将数据库中的
EmailConfirmed
布尔值设置为True
,并且 - 我们从 ASP.NET Core 的早期版本迁移了数据,其中两个电子邮件字段
Email
和NormalizedEmail
未设置并保留null
.
一旦我们填充了缺失的电子邮件字段,并且 运行 确认步骤——或手动将标志更改为 True
——密码重置电子邮件开始工作。