Home > ASP.Net > Send Confimation Email after Create User

Send Confimation Email after Create User


try this example:

<asp:CreateUserWizard ID="CreateUserWizard1" runat="server" LoginCreatedUser="false" DisableCreatedUser="true"         
         MailDefinition-BodyFileName="signupmail.txt" OnSendingMail="CreateUserWizard1_OnSendingMail">
            <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
            <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">

** signupmail.txt:

Thank you for signing up for a new account at my site. To complete your registration, please follow the link below:


protected void CreateUserWizard1_OnSendingMail(object sender, MailMessageEventArgs e)
        // Create an SQL connection object
        using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString))
            // Create a command to get the user ID of the new user
            SqlCommand command = new SqlCommand("SELECT m.UserId FROM aspnet_Membership m INNER JOIN aspnet_Users u ON m.UserId = u.UserId WHERE u.LoweredUserName= LOWER(@UserName) AND m.Email = @Email AND m.IsApproved = 0",conn);

            // Add the parameters
            command.Parameters.AddWithValue("@UserName", MBTCreateUserWizard.UserName.ToString());
            command.Parameters.AddWithValue("@Email", MBTCreateUserWizard.Email.ToString());

            // Execute the query
            SqlDataReader reader = command.ExecuteReader();

            if (reader.HasRows)
                // Read the next row

                string userid = reader[0].ToString();

                // Inject the user ID into the mail body
                e.Message.Body = e.Message.Body.Replace("<%NEWUSERID%>", userid);

            // Close everything

** In authorise.aspx Page

protected void Page_Load(object sender, EventArgs e)
        // Get the user ID from the request string
        string userid = Request["u"];

        if (userid != null && userid != "")
            // Update the account to activate it
                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString))
                    SqlCommand command = new SqlCommand("UPDATE aspnet_Membership SET IsApproved=1 WHERE UserId=@UserId", conn);

                    command.Parameters.AddWithValue("@UserId", userid);


                // Success, inform or redirect
            catch (SqlException se)
                // Provide appropriate user feedback
            // Provide appropriate user feedback

In web.config:

<membership defaultProvider="MyProvider" userIsOnlineTimeWindow="25">
    <add name="MyProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="Bag_ConnStr" applicationName="/" enablePasswordRetrieval="true" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Clear" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="5" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>

Good Luck

Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: