Skip Navigation LinksHome > Categories > Code from a Category

Disable sending emails when new user created in local pc



User Name: jamest85
Name: James Tang
Contact Me: www.datawebcoder.com/ContactUs.aspx
Home Page: www.datawebcoder.com
Google Apps for Work Partner, Certified Zoho CRM Consultant. 7 years experience on Zoho consulting, implementation, and programming using C#, VB, Php..., 15 years of total IT experience including prog... [More]
Viewed Times: 1486
Add Date: 02/17/2010
If using CreateUserWizard control, we might need send an welcome email to the new user and also send an email to inform the site owner, but we don't want this happens in local pc, below post shows how to send emails and how to disable it.
This is the top part of a CreateUserWizeard looks like:
 
.....
.....

From above code, 3 lines help us sending email to the new user:
MailDefinition-BodyFileName ="~/EmailTemplates/Register.txt"
MailDefinition-Subject="Registration Confirmation - From www.yoursite.com"
MailDefinition-From ="info@yoursite.com"

The Register.txt looks like this:
-----------------------------------------starts---------------------------------------------
Dear <% UserName %>:
Thank you for registration!
Please make sure you keep below login information.
username: <% UserName %>
passwrod: <% Password %>
To reset your password, you must answer the following question:
Password Question: <%PasswordQuestion%>
Password Answer: <%PasswordAnswer%>
-------------------------------------------ends--------------------------------------------
Another line helps us adding other function when sending emails:
OnSendingMail="CreateUserWizard1_SendingMail", code behind:
 protected void CreateUserWizard1_SendingMail(object sender, MailMessageEventArgs e)
    {
        string sUserName = CreateUserWizard1.UserName.ToString();
        
       //yourNameSpace.Config.isLiveMode is the value from .config file appSettings.
        if ((string.Compare("True", yourNameSpace.Config.isLiveMode) == 0))
        {
           //inform new user
           e.Message.IsBodyHtml = false;
           e.Message.Body = e.Message.Body.Replace("<%PasswordQuestion%>", 
                                        CreateUserWizard1.Question);
           e.Message.Body = e.Message.Body.Replace("<%PasswordAnswer%>", 
                                        CreateUserWizard1.Answer);

           //inform owner 
            yourNameSpace.Email.newRegister(sUserName); 
        }
        else
            e.Cancel = true ; //won't send email.
    }
The e.Cancel = true will stop sending any emails if it is in local development pc.

Post a Comment

Name: (Optional)
Email: (Optional, you can get an email if somebody replys your comments)*
Email me if somebody respons my comment below:
Details**:
Enter Text
as Below:
(case insensitive, if hard to read, click the "get a new one" button)
 
    
* Your email address will not be shared with any third parties for any reason.
** Maximum 1000 charactors.