我希望有人可以为我提供一些帮助,我有一个用户可以注册的应用程序,并在register.aspx.vb文件中包含未注释的行以允许发送电子邮件。
Protected Sub CreateUser_Click(sender As Object, e As EventArgs)
Dim userName As String = Email.Text
Dim manager = Context.GetOwinContext().GetUserManager(Of ApplicationUserManager)()
Dim signInManager = Context.GetOwinContext().Get(Of ApplicationSignInManager)()
Dim user = New ApplicationUser() With {.UserName = userName, .Email = userName}
Dim result = manager.Create(user, Password.Text)
If result.Succeeded Then
' For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
Dim code = manager.GenerateEmailConfirmationToken(user.Id)
Dim callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request)
manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=""" & callbackUrl & """>here</a>.")
signInManager.SignIn(user, isPersistent := False, rememberBrowser := False)
IdentityHelper.RedirectToReturnUrl(Request.QueryString("ReturnUrl"), Response)
Else
ErrorMessage.Text = result.Errors.FirstOrDefault()
End If
End Sub
问题是,我需要添加类似于http://www.asp.net/identity/overview/features-api/account-confirmation-and-password-recovery-with-aspnet-identity#email的电子邮件设置,但不知道如何调用它,这是否需要进入EmailService下的Identity.config?我是否需要在web.config ????
中添加内容答案 0 :(得分:0)
将详细信息添加到您的web.config:
<system.net>
<mailSettings>
<smtp from=“-your-sending-email-address-">
<network defaultCredentials="false" host=“-mail.example.com-" password=“—password-" userName=“—email—account-" />
</smtp>
</mailSettings>
</system.net>
更多信息:https://msdn.microsoft.com/en-us/library/w355a94k(v=vs.110).aspx