J-O Eriksson

Community Server on my mind

News

Subscribe via FeedBurner

Subscribe via email

<script type="text/javascript"><!-- google_ad_client = "pub-6305396639794057"; google_ad_width = 120; google_ad_height = 240; google_ad_format = "120x240_as"; google_ad_type = "text_image"; google_ad_channel ="5472463295"; google_color_border = "FFFFFF"; google_color_link = "0000FF"; google_color_bg = "FFFFFF"; google_color_text = "000000"; google_color_url = "008000"; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>

Subscribe in NewsGator Online

Subscribe in Bloglines

Add to Google

<script type="text/javascript" src="http://embed.technorati.com/embed/tb2ijzxn26.js"></script>

Blogs I read

Links

CS2: Mass mailing to all users, but allow user to opt-out

So you want to send all your users of your Community Server community i.e. a newsletter? But some users may contact you and say they don't want the newsletters anymore.

In Community Server you can send mass mail to all users of a certain role. By default all registered users is added to the role - you've guessed it - "Registered Users". But if you use that role for your mass mailings you won't be able to exclude users on demand. Taking them out of the role "Registered Users" would not be a good idea. So you would need another role to use for your mass mailings. Let's say we want to use a role called "Newsletter" for the mass mailings. We would then need a way to put all newly registered users into that role as well. Don't worry, you don't need to open the source code of CS and modify it. Just open communityserver.config in your favourite editor. In the Core section you can se a row with the following:

defaultRoles = "Everyone;Registered Users"

This row determines which role a user is added to at registration. So we add our "Newsletter" role to it, like:

defaultRoles = "Everyone;Registered Users;Newsletter"

That's it! Now all of your users is added to the "Newsletter" role at registration, and you can send mass mail to it. If someone wants to opt-out, just remove them from the "Newsletter" role.

Yeah, I know, I forgot one thing. You might of course have a whole lot of existing users already, how do you add those? One way to do that is with a T-SQL script.

CREATE TABLE #NewRole (
 [UserId] [uniqueidentifier] NOT NULL ,
 [RoleId] [uniqueidentifier]
)

INSERT INTO #NewRole (UserID)
SELECT UserID FROM aspnet_Users WHERE ApplicationID = 'your applicationID here'
 AND UserID <> 'your anonymous UserID here'
 AND RoleID <> 'your Newsletter roleID herer'

UPDATE #NewRole
 SET RoleID = 'your Newsletter roleID here'

DROP TABLE #NewRole

INSERT INTO aspnet_UsersInRoles (UserID, RoleID)
   SELECT UserID, RoleID FROM #NewRole

The red text should be replaced with:

AplicationID - ApplicationID from your aspnet_Applications table (if you have more than one be sure to choose the right one)

Anonymous UserID - UserID from your aspnet_Users table. There would be one anonymous user per application. So the same here if you have multiple applications, be sure to get the correct one.

Newsletter RoleID - RoleID from your aspnet_Roles table (The new role you created for massmailing). Again there's one set of roles collection for each application.

Note: Before you go ahead and run the T-SQL on your live DB, you might want to try it in a test environment first, to see that it works as expected. And of course make sure you do a DB Backup before you run it live. You could also test it on the live DB by first omitting the last INSERT statement, and adding a SELECT * FROM #NewRole before the DROP TABLE statement. That would list all the additions that will be made to the aspnet_UserInRoles table. Such a test script would look like:

CREATE TABLE #NewRole (
 [UserId] [uniqueidentifier] NOT NULL ,
 [RoleId] [uniqueidentifier]
)

INSERT INTO #NewRole (UserID)
SELECT UserID FROM aspnet_Users WHERE ApplicationID = 'your applicationID here'
 AND UserID <> 'your anonymous UserID here'
 AND RoleID <> 'your Newsletter roleID herer'

UPDATE #NewRole
 SET RoleID = 'your Newsletter roleID here'

SELECT * FROM #NewRole

DROP TABLE #NewRole

If any of you readers are more skilled in T-SQL then me, you might have better suggestions for this? Write a comment to this post and let me know.

Comments

No Comments