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.