Mail.SmtpClient in createuserwizard_sendingmail event sending 2 copies of email, why?

Posted on 2012-09-13
Last Modified: 2012-09-14
Hello all I have a creatuserwizard on my site that fires off an email when someone registers that requires them to click a link to activate the account.  That all works fine.
I have the MailDefinition setup on the control itself that builds the body of the email, sender etc. In my webconfig I have the mailsettings for server host, port, sending user,, etc.
On the sedndingmail event I have the following code. I always get 2 copies of the email.  What am I doing wrong in teh code below that is causing it?  I can't seem to eliminate the right line.
 Dim newUserAccount As MembershipUser = Membership.GetUser(CreateUserWizard1.UserName)
        Dim newUserAccountId As Guid = DirectCast(newUserAccount.ProviderUserKey, Guid)
        Dim domainName As String = Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath
        Dim confirmationPage As String = "/account/EmailVerification.aspx?UserID=" & newUserAccountId.ToString()
        Dim url As String = domainName & confirmationPage
        e.Message.Body = e.Message.Body.Replace("<%VerificationUrl%>", url)
        Dim obj As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient
        Dim Mailmsg As New System.Net.Mail.MailMessage
        obj.EnableSsl = True
        e.Cancel = True
Question by:MVaughn12
    1 Comment

    Accepted Solution

    Well I got it working found a post out on the web that had the same issue on a button click, but using similar code. I took the Handles CreateUserWizard1.SendingMail out of my code and user now only gets 1 copy of the email.  Code must have been firing twice?

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
    Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now