• Hello and welcome to our new forums. We upgraded our forum sites to a more robust and modern system which we hope you will enjoy. Be sure to check out your profile by clicking the button on the top right and configure your preferences, signature, time zone, avatar, etc. as you wish. If you need help with using this new forum'ware try the help link on the bottom right.

    Click here to review your account now.

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