Fixing the invite email template in Alfresco Share

2011-04-05

In Alfresco Share you can easily invite both internal and external users to a Collaboratio site. Alfresco will create the user account with accompanying password if the user doesn’t already exist. The invite is sent as an email message to the invitees containint links to accept or reject the invite, from thereon the user can start to collaborate in information in the collaboration site.

The template user for the invite email is found in Repository> Data Dictionary> Email Templates> invite and is named invite-email.ftl. You can find it by clicking the Repository button in Alfresco Share toolbar, and then navigate to invite-email.ftl. You can edit this file online if you want to. Simple stuff, like changing the sender organisation name, most of us can do, but it is easy to do more.

The confirmation link created is using the server name of the server that the user doing the invite is currently using. This is in most cases correct, but you may want to direct internal and external users to different share servers (still connecting to same repository). It may be because you need to set up different authentication methods, or you have customized share to look different depending on if the users are external or internal.

http://alfresco.example.com/share/page/accept-invite?inviteId=jbpm$156&inviteeUserName=peter%40example.com&siteShortName=examplesite&inviteTicket=610b4819-0153-4406-9d85-0357e5ee65d3


The example above shows what the link may look like, in this case the alfresco.example.com is picked up from the server the inviting user is logged into when doing the invite. But in our case we want all external users to use alfresco-external.example.com. The can easily be achieved using freemarker code. If you never have used freemarker before don’t hesitate, if you know some html and/or javascript you will qiuckly pick up. Freemarker is also well documented.

This is what the template can look like, I’ve commented inline to explain.

<#assign inviterPersonRef=args["inviterPersonRef"]/>
<#assign inviterPerson=companyhome.nodeByReference[inviterPersonRef]/>
<#assign inviteePersonRef=args["inviteePersonRef"]/>
<#assign inviteePerson=companyhome.nodeByReference[inviteePersonRef]/>
<#-- Remove server name from the link-->
<#assign yesLink=args["acceptLink"]?substring(args["acceptLink"]?index_of("/share")) />
<#assign noLink=args["rejectLink"]?substring(args["rejectLink"]?index_of("/share")) />
<#assign userName=args["inviteeUserName"]?string />
<#-- Set server name depending on if user is internal or external -->
<#if userName?index_of("@") > 0 >
<#-- All external user has their email address as username, check for this -->
    <#assign serverName="http://alfresco-external.example.com" />
<#else>
    <#assign serverName="https://alfresco.example.com" />
</#if>

Hello ${inviteePerson.properties["cm:firstName"]},

You have been invited by ${inviterPerson.properties["cm:firstName"]} ${inviterPerson.properties["cm:lastName"]} to join the '${args["siteName"]}' site.

Your role in the site will be ${args["inviteeSiteRole"]}.

To accept this invitation click the link below.
<#-- Append yes link to server name (that is different if internal or external user) -->
${serverName}${yesLink}

<#if args["inviteeGenPassword"]?exists>
and enter the following information:

Username: ${args["inviteeUserName"]}
Password: ${args["inviteeGenPassword"]}

We strongly advise you to change your password when you log in for the first time.

</#if>
If you do not want to join the site then click here:
<#-- Append no link to server name -->
${serverName}${noLink}

Create a bookmark after accepting for this server for use when you log in next time
${serverName} <#-- This is important, manu users miss where to navigate once they have accepted -->
You can create bookmarks for any place in Alfresco Share if you would like to reach you information quickly.

Regards,

${inviterPerson.properties["cm:firstName"]} ${inviterPerson.properties["cm:lastName"]} 
Company

Note that you now can put a link to root in the Alfesco Share server. I’ve noticed that many times there are some confusion on where to navigate once the user has accepted. Users will find the invite email again, and the only clickable link in there is the invite, this results in an error since they already have accepted. Unfortunately html formatted emails are not supported by Alfresco yet, so the outgoing email will be plain text formatted. Another tip can be to to put a link it a help page in the wiki (of you help page is named Getting Started) `${serverName}/share/page/site/publicsitename/wiki-page?title=Getting_Started` This must be a link to a public site so that all invited users have read access. I have configured Alfesco so that external user id:s is base on their email adress. You can do this by creating a file in tomcat/shared/classes/alfresco/extension named invite-context.xml with the content

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
    <bean id="nameBasedUserNameGenerator" class="org.alfresco.repo.security.authentication.NameBasedUserNameGenerator">
            <!-- name patterns available:
           %lastName%,  lower case last name
           %firstName%, lower case first name
           %emailAddress% email address
             %i% lower case first name inital
         -->
        <property name="namePattern">
          <value>%emailAddress%</value>
        </property>
        <property name="userNameLength">
            <value>10</value>
        </property>
    </bean>  
</beans>

You can also add fixed text, for example if you would like to have the prefix ext you can use ext_%firstName%_%lastName%.

Hope that this have given you some ideas. There is of course so much more you can do, for example add links to support, links to searches, adding a second language and more. Put some work into this template, as it often is the first thing users get in contact with when starting to user Alfresco Share. Good luck.