问题描述
我正在开发一个Asp.net Web应用程序。在我的应用程序中,我正在设置用户电子邮件确认和密码重设功能。我正在使用Asp.net内置的身份系统。可以在此链接之后启用这些功能 - 。但是要遵循此链接,。但是没关系,我只想知道asp.net身份系统中只有一件事情。那是发送电子邮件。根据Visual Studio中的注释行,我可以发送如下所示的重置密码邮件。 await UserManager.SendEmailAsync(user。 Id,重置密码,请通过点击< a href = \+ callbackUrl +\> here< / a>重置您的密码);
该行简单易读。但问题是我可以在哪里配置发件人电子邮件凭据?用什么设置发送电子邮件?如何更改发件人电子邮件?我不能跟随链接,因为天蓝色的链接被打破了。请帮我在哪里可以设置和更改这些设置?
我尝试在web.config中添加此设置
system.net>
< mailSettings>
< smtp from =testing@gmai.com>
< network host =smtp.gmail.compassword =testingport =587userName =testingenableSsl =true/>
< / smtp>
< / mailSettings>
< /system.net>
但现在发送电子邮件。
最后我找到了解决方案。
我在这里添加了web.config中的电子邮件设置
< system.net>
< mailSettings>
< smtp from =testing@gmai.com>
< network host =smtp.gmail.compassword =testingport =587userName =testingenableSsl =true/>
< / smtp>
< / mailSettings>
< /system.net>
然后我更新了
public class EmailService:IIdentityMessageService
{
public Task SendAsync(IdentityMessage message)
{
//在这里插入您的电子邮件服务发送电子邮件。
返回Task.FromResult(0);
}
}
在App_Start文件夹中的IdentityConfig.cs中
public class EmailService:IIdentityMessageService
{
public Task SendAsync(IdentityMessage message)
{
//在这里插入您的电子邮件服务发送电子邮件。
SmtpClient client = new SmtpClient();
return client.SendMailAsync(email from web.config here,
message.Destination,
message.Subject,
message.Body);
}
}
当我发送电子邮件时,它自动使用web.config中的设置。
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. 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>");
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 cause azure link is broken. Please help me where can I set and change those settings please?
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.
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>
Then I updated
public class EmailService : IIdentityMessageService
{
public Task SendAsync(IdentityMessage message)
{
// Plug in your email service here to send an email.
return Task.FromResult(0);
}
}
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);
}
}
When I send email, it auto use the settings from the web.config.
这篇关于如何为ASP.NET Identity UserManager.SendEmailAsync配置发件人电子邮件凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!