Emailing link SMTP to new user RRS feed

  • Question

  • User-1793215261 posted


    I have the following in my Register.aspx.vb code to register a new user in my SQL database and to send an email to the user asking him to confirm his email address by clicking on a link:

    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)
                Dim target = String.Format("~/success.aspx?Email={0}", Email.Text)
                Response.Redirect(target, True)
                ErrorMessage.Text = result.Errors.FirstOrDefault()
            End If
        End Sub

    But how do I intergrate other important SMTP mail server information, such as (but not limited to):

    Dim myMessage As New MailMessage 
    Dim Smtpserver As New SmtpClient 
    Dim CC As MailAddress = New MailAddress("myemail@mysite.com")
    myMessage.CC.Add(New MailAddress("myemail@mysite.com")) 
    myMessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
    myMessage.IsBodyHtml = True, myMessage.Priority = MailPriority.Normal 
    myMessage.Priority = MailPriority.Normal
    Smtpserver.DeliveryMethod = SmtpDeliveryMethod.Network
    Smtpserver.Host = ("nameOfServer")
    Smtpserver.Port = 25
    Smtpserver.EnableSsl = True
    Dim basicAuthenticationInfo As New System.Net.NetworkCredential("info@mysite.com", "myPassword")
    Smtpserver.Credentials = basicAuthenticationInfo
    myMessage = Nothing
    Smtpserver = Nothing    

    Thank you!

    Monday, August 12, 2019 1:12 PM

All replies