步骤一:创建自定义邮件模板
示例代码:
@model MyProject.Models.EmailConfirmationViewModel
Email Confirmation
Hello @Model.UserName,
Thank you for registering on MyProject. Please confirm your email by clicking the following link:
@Html.ActionLink("Confirm your account", "ConfirmEmail", "Account", new { userId = Model.UserId, code = Model.Code }, null)
Best regards,
The MyProject Team
步骤二:将自定义模板设置为默认值
services.Configure(options =>
{
options.EmailTemplates.ConfirmAccountEmailTemplate = "/Views/EmailTemplates/ConfirmAccount.cshtml";
});
此代码行将自定义邮件模板路径设置为ASP .NET Identity默认的账户确认邮件模板。
注意:确保文件路径正确无误。
步骤三:发送带有自定义模板的确认邮件
var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Scheme);
var model = new EmailConfirmationViewModel
{
UserName = user.UserName,
UserId = user.Id,
Code = code,
CallbackUrl = callbackUrl
};
此代码行使用ASP