Monday, August 1, 2011

Send an Email to an Entire Alfresco Share Site

I had the need to send the users of an Alfresco Share site an email; however, doing so is not readily apparent.  It is pretty easy once you know the convention:

GROUP_site_siteId


This differs from the Alfresco Explorer groups which follow the pattern:

GROUP_groupId

Here is an example of what a site group identifier should look like if the site id is transportation:

GROUP_site_transportation

If you're working in the javascript world or just want to hardcode things together, you can construct the group identifier using the above as a template.  However, in the java world, Alfresco provides us with the SiteService. If you know the short name of your site, you can retrieve the string identifier for the site group. In my case, I retrieved the short name of the site from the nodeRef passed into a behavior.

Here is the code I used to do this:

// To
 SiteInfo siteInfo = siteService.getSite( nodeRef );
 String siteShortName = siteInfo.getShortName();
 String siteGroup = siteService.getSiteGroup( siteShortName );
   
 // Send email notice detailing the state change
 Action emailAction = actionService.createAction( MailActionExecuter.NAME );
 
 emailAction.setParameterValue( MailActionExecuter.PARAM_SUBJECT, subject );
 emailAction.setParameterValue( MailActionExecuter.PARAM_TO_MANY, siteGroup );
 emailAction.setParameterValue( MailActionExecuter.PARAM_TEXT, "Hello world." );
 
 actionService.executeAction( emailAction, nodeRef );

No comments:

Post a Comment