Reputation: 2964
In my Startup.cs
I have
services.AddTransient<Microsoft.AspNetCore.Identity.UI.Services.IEmailSender, EmailSender>(i =>
new EmailSender(
Configuration["EmailSender:Host"],
Configuration.GetValue<int>("EmailSender:Port"),
Configuration.GetValue<bool>("EmailSender:EnableSSL"),
Configuration["EmailSender:UserName"],
Configuration["EmailSender:Password"]
));
and I have a class
public class EmailSender : IEmailSender
{
/* snip */
public Task SendEmailAsync(string email, string subject, string htmlMessage)
{
var client = new SmtpClient(_Host, _Port)
{
Credentials = new NetworkCredential(_UserName, _Password), EnableSsl = _EnableSSL
};
return client.SendMailAsync(
new MailMessage(_UserName, email, subject, htmlMessage) { IsBodyHtml = true }
);
}
}
I'm running smtp4dev
.
When I try to register a user or forget a password no e-mail is sent. In a breakpoint in SendEmailAsync
is not hit.
I don't understand what I need to do to get this thing to send an e-mail. Do you? And if so then can you tell me what it is? Is this documented somewhere?
Upvotes: 4
Views: 3306
Reputation: 21
If you're certain emails are not being sent for both email verifications and password resets, then please ignore this suggestion. However, if your emails get sent for email verifications but don't get sent for password resets, then please read on.
Does a break point in the constructor of your IEmailSender get hit? If so then make sure that the user you're trying to reset the password for has a verified email address. If an email address is not verified Identity will not send any of the other email notifications.
Alternatively, temporarily disable confirmed accounts and see if your emails are being sent.
services.AddDefaultIdentity<ApplicationUser>(options =>
{
options.SignIn.RequireConfirmedAccount = false;
})
Upvotes: 2
Reputation: 84
Please do add the code snippet where and how you are using EmailSender class , since you have asked for the documentation , which you can refer to this https://learn.microsoft.com/en-us/aspnet/identity/overview/features-api/account-confirmation-and-password-recovery-with-aspnet-identity
Upvotes: 0