Wai*_*ein 4 email asp.net-mvc email-client asp.net-identity
我正在开发一个Asp.net Web应用程序.在我的应用程序中,我正在设置用户电子邮件确认和密码重置功能.我正在使用内置身份系统的Asp.net.这些功能可以通过以下链接启用 - https://www.asp.net/identity/overview/features-api/account-confirmation-and-password-recovery-with-aspnet-identity根据Visual Studio中的提及.
但要遵循它,这个链接就被打破了 - https://azure.microsoft.com/en-us/gallery/store/sendgrid/sendgrid-azure/.但没关系,我只想知道asp.net身份系统中的一件事.那是发送电子邮件.根据Visual Studio中的注释行,我可以发送如下所示的重置密码电子邮件.
await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>");
Run Code Online (Sandbox Code Playgroud)
这条线简单易读.但问题是我在哪里可以配置发件人电子邮件凭据?它用于发送电子邮件的设置是什么?如何更改发件人电子邮件?我也无法关注该链接,因为Azure链接已损坏.我在哪里可以设置和更改这些设置?
我尝试在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>
Run Code Online (Sandbox Code Playgroud)
但现在发送电子邮件.
最后我找到了解决方案.
我在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>
Run Code Online (Sandbox Code Playgroud)
然后我更新了
public class EmailService : IIdentityMessageService
{
public Task SendAsync(IdentityMessage message)
{
// Plug in your email service here to send an email.
return Task.FromResult(0);
}
}
Run Code Online (Sandbox Code Playgroud)
在App_Start文件夹中的IdentityConfig.cs中
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);
}
}
Run Code Online (Sandbox Code Playgroud)
当我发送电子邮件时,它会自动使用web.config中的设置.
| 归档时间: |
|
| 查看次数: |
14827 次 |
| 最近记录: |