Learn More





Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesSending system emails from codeSending system emails from code
New Post
6/21/2013 5:24 AM

When you create a user using the gui, an email is sent ou to that user containing (amongst others) his password. When I add a user programmatically using the CreateUser call, this message is not sent (and the default roles aren't assigned, but I've already fixed that). Are there more differences between CreateUser and creating a user manually I should be aware of??

Is there a way to send these messages? It seems a daunting taks to retreive the admin e-mail address (sender), message subject and body from the resx files (in the correct language, on system, host and site level), parse both texts and send it out. just to recreate default dnn bahaviour.

New Post
6/24/2013 8:11 AM
I've found that DotNetNuke.Services.Mail.Mail.SendMail(user, MessageType.UserRegistrationPublic, portalSettings) does exactly what I need.
Except that I throws an "Object reference not set to an instance of an object."-error.

I guess there is some property of the user that needs to be set?
I already set:
  •   user.PortalID = portalId;
  •   user.IsSuperUser
  •   user.FirstName
  •   user.LastName
  •   user.Email
  •   user.Username
  •   user.DisplayName
  •   user.Profile.FirstName (= user.FirstName)
  •   user.Profile.LastName (= user.LastName)
  •   user.Profile.PreferredLocale (although I believe this can be null)
  •   user.Profile.PreferredTimeZone
  •   user.Membership.Approved
  •   user.Membership.CreatedDate
  •   user.Membership.IsOnLine
  •   user.Membership.Password
What other properties do I need to set to be able to sent the UserRegistrationPublic email?


var portalSettings = new PortalSettings(portalId);

var user = new UserInfo();

user.PortalID = portalId;
user.IsSuperUser = false;
user.FirstName = "John";
user.LastName = "Smith";
user.Email = "[email protected]";
user.Username = "johns";
user.DisplayName = "John";

user.Profile.FirstName = user.FirstName;
user.Profile.LastName = user.LastName;
user.Profile.PreferredLocale = portalSettings.DefaultLanguage;
user.Profile.PreferredTimeZone = portalSettings.TimeZone;

var oNewMembership = new UserMembership();
oNewMembership.Approved = true;
oNewMembership.CreatedDate = System.DateTime.Now;
oNewMembership.Email = user.Email;
oNewMembership.Username = user.Username;
oNewMembership.IsOnLine = false;
oNewMembership.Password = UserController.GeneratePassword();
user.Membership = oNewMembership;

if (UserCreateStatus.Success == UserController.CreateUser(ref user))
    // User created successfully
    DataCache.ClearPortalCache(user.PortalID, false);
    // send email to user
    DotNetNuke.Services.Mail.Mail.SendMail(user, MessageType.UserRegistrationPublic, portalSettings);
New Post
6/24/2013 9:13 AM
Hmmm. It's not releated to the new user, but to the portal. Token [Portal:URL] can not be replaced.... still searching for the cause...
New Post
6/25/2013 8:48 AM
The problem is that the portalSettings.PortalAlias property is null. (Strangely the portalSettings.DefaultPortalAlias *is* set). I Think this is a bug.

I've been able to 'fix' it by filling the PortalAliases property with the DefaultPortalAlias.
I don't know how trustworthy this fix is, there is probably some difference between HTTPAlias and DefaultAlias.

var portalSettings = new PortalSettings(portalId);
if (portalSettings.PortalAlias == null)
portalSettings.PortalAlias = new PortalAliasInfo();
portalSettings.PortalAlias.HTTPAlias = portalSettings.DefaultPortalAlias;
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesSending system emails from codeSending system emails from code

These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
Try Evoq
For Free
Start Free Trial
a Demo
See Evoq Live
Need More Information?