• I removed the www from the URL, please update your bookmarks and pay attention to the bottom of the screen if using Google Chrome to allow push notifications again.

Sending confirmation email to user

keymaker

Member
Joined
Aug 13, 2014
Messages
12
Programming Experience
Beginner
Hello

I am aiming to use Microsoft's AspNet Identity template to send an email confirmation link to a newly registered user. This is the code I have in my register_test.aspx.vb file:

VB.NET:
 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
            
            Dim code = manager.GenerateEmailConfirmationToken(user.Id)
            Dim callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request)
          
            manager.SendEmail(user.Id, $"Confirm your account", "Dear {Email}<br><br>Please confirm your account by clicking <a href=""" & callbackUrl & """>here</a>. <br>Your account details are provided below: <br><br>Email:{Email}<br>Password:{Password}")

              signInManager.SignIn(user, isPersistent:=False, rememberBrowser:=False)
            ' IdentityHelper.RedirectToReturnUrl(Request.QueryString("ReturnUrl"), Response) 'This is the original line of code

            Dim target = String.Format("~/success_test.aspx?Email={0}", Email.Text)

            Response.Redirect(target, True)

        Else
            ErrorMessage.Text = result.Errors.FirstOrDefault()
        End If
    End Sub
On clicking the button, the user is redirected to success_test.aspx which tells him to click on a link to confirm his email address. At the moment, these emails are not sent anywhere because my files are not uploaded to my Web hosting server, but I would like them to go to a folder on my C drive so I can see what they look like. Therefore, I have this in my Web.config:

VB.NET:
<system.net>
    <mailSettings>
      <smtp deliveryMethod="SpecifiedPickupDirectory" from="info@mysite.net">
        <specifiedPickupDirectory pickupDirectoryLocation="C:\TempMail"/>
      </smtp>
    </mailSettings>
  </system.net>
The emails that contain the link, do not arrive in that TempMail folder on my C drive. I am not using Azure SendGrid, so do I need to add SMTP code in my register.aspx.vb file or Web.config?

Thank you.
 
Top Bottom