Email Campaigns and Users

Posted by Community Admin on 03-Aug-2018 18:05

Email Campaigns and Users

All Replies

Posted by Community Admin on 13-Nov-2011 00:00

How do we send out an email campaign to sitefinity users? I currently have users under the role of customers, separated into 3 types of customers. I would like to send each type of customer a different email campaign. So far, I have only been able to send an email to all users. Is there any way to filter the users in the email campaign. Any feedback would help. Thanks.

Posted by Community Admin on 16-Nov-2011 00:00

Hi Tin,

That's a tough one, the default functionality offers you to pull from a Dynamic list that can be a list of users belonging to any of the User providers, but this will get all users created for that Provider, without the option to filter them by role. However, it's possible to create a new mailing list and fill it with Sitefinity users that belong to a certain role through code. Please find below a code sample I've prepared for you which does exactly this.

public void CreateMailingListFromUsersInRole(string rolename, string mailingListName, string subject, string reminder, string defaultFromName, string defaultReplyToEmail, bool sendWelcome, bool sendGoodbye)
       
           var subscribersManager = NewslettersManager.GetManager();
           var roleManager = RoleManager.GetManager();
           //Get the ID of the specified role
           var myroleID = roleManager.GetRole(rolename).Id;
           //Get all users in that Role
           var selectedUsersList = roleManager.GetUsersInRole(myroleID);
 
           //Create a new Subscribers List and set its properties
           var mailingList = subscribersManager.CreateMailingList();
           mailingList.Title = mailingListName;
           mailingList.DefaultSubject = subject;
           mailingList.SubscriptionReminder = reminder;
           mailingList.DefaultFromName = defaultFromName;
           mailingList.DefaultReplyToEmail = defaultReplyToEmail;
           mailingList.SendGoodByeMessage = sendGoodbye;
           mailingList.SendWelcomeMessage = sendWelcome;
           subscribersManager.SaveChanges();
 
 
           foreach (var myUser in selectedUsersList)
           
               //Get the user DisplayName (Firstname+Lastname)
               var displayName = UserProfilesHelper.GetUserDisplayName(myUser.Id);
 
               //Create a new Subscriber and set his/her properties
               var subscriber = subscribersManager.CreateSubscriber(true);
               subscriber.FirstName = displayName.Split(' ').First();
               subscriber.LastName = displayName.Split(' ').Last();
               subscriber.Email = myUser.Email;
               //Add the new Subscriber to the created Mailing List
               mailingList.Subscribers.Add(subscriber);
           
            
           subscribersManager.SaveChanges();
       

You can place the code in a WebForm and create some labels where the properties can be set, and a create button which will execute the code. If there's anything else we can help you, please let us know.

Regards,
Boyan Barnev
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 05-Mar-2013 00:00

Trying to avoid recreating mailing list each time (since it is not a dynamic list).

How about creating new or overriding existing UsersDynamicListProvider?
This should be more flexible approach. Please let me know if it is possible and throw some code example too. Thanks!

This thread is closed