cancel
Showing results for 
Search instead for 
Did you mean: 

Using HTML in Email Notification Template

akbhaskar
Champ in-the-making
Champ in-the-making
Hi,

We are using 3.3 CE.
I have modified the notify email template to include bold formatting tags <b>. The template code is:
<b>A new document '${document.name}'</b>, is available.
It was added by ${person.properties.firstName}<#if person.properties.lastName?exists> ${person.properties.lastName}</#if>.

Regards

Alfresco

but the email that the users are getting is plain text with <b> and </b> tags. Is there some configuration that I need to do to enable HTML content in outbound email.

Regards,
Ashish
4 REPLIES 4

savic_prvoslav
Champ on-the-rise
Champ on-the-rise
code is like this:

MimeMessageHelper message = new MimeMessageHelper(mimeMessage,
         true);
      System.out.println(email + " " + from);
      message.setTo(email);
      message.setSubject(subject);
      System.out.println("body :" + body);
      message.setText(body, true);
      message.setFrom(from);
      message.setReplyTo(new InternetAddress(from));

and this is not the code that is used in alfresco, they use message.setText(body); and mail is not HTML Smiley Sad

akbhaskar
Champ in-the-making
Champ in-the-making
code is like this:

MimeMessageHelper message = new MimeMessageHelper(mimeMessage,
         true);
      System.out.println(email + " " + from);
      message.setTo(email);
      message.setSubject(subject);
      System.out.println("body :" + body);
      message.setText(body, true);
      message.setFrom(from);
      message.setReplyTo(new InternetAddress(from));

and this is not the code that is used in alfresco, they use message.setText(body); and mail is not HTML Smiley Sad

Thank you for the detailed code. Where can I find this and do I need to build alfresco after modification?

savic_prvoslav
Champ on-the-rise
Champ on-the-rise
Well I did not find way to override this problem so  org.alfresco.web.bean.users.TemplateMailHelperBean
this is the class, you can it is located inside of alfesco-web-client.jar, and you can just rebuld it( no need to rebuild all of the alfresco) .
 public void notifyUser(NodeRef person, NodeRef node, final String from, String roleText)
   {
      final String to = (String)this.getNodeService().getProperty(person, ContentModel.PROP_EMAIL);
     
      if (to != null && to.length() != 0)
      {
         String body = this.body;
         if (this.usingTemplate != null)
         {
            FacesContext fc = FacesContext.getCurrentInstance();
           
            // use template service to format the email
            NodeRef templateRef = new NodeRef(Repository.getStoreRef(), this.usingTemplate);
            ServiceRegistry services = Repository.getServiceRegistry(fc);
            Map<String, Object> model = DefaultModelHelper.buildDefaultModel(
                  services, Application.getCurrentUser(fc), templateRef);
            model.put("role", roleText);
            model.put("space", node);
            // object to allow client urls to be generated in emails
            model.put("url", new BaseTemplateContentServlet.URLHelper(fc));
           
            body = services.getTemplateService().processTemplate("freemarker", templateRef.toString(), model);
         }
         this.finalBody = body;
        
         MimeMessagePreparator mailPreparer = new MimeMessagePreparator()
         {
            public void prepare(MimeMessage mimeMessage) throws MessagingException
            {
               MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
               message.setTo(to);
               message.setSubject(subject);
               message.setText(finalBody,true); //HIRE IS THE CHANGE.
               message.setFrom(from);
            }
         };
        
         if (logger.isDebugEnabled())
            logger.debug("Sending notification email to: " + to + "\n…with subject:\n" + subject + "\n…with body:\n" + body);
        
         try
         {
            // Send the message
            this.getMailSender().send(mailPreparer);
         }
         catch (Throwable e)
         {
            // don't stop the action but let admins know email is not getting sent
            logger.error("Failed to send email to " + to, e);
         }
      }
   }

this would be in your case, because you are using notifying the users of space change. this change would not take more then 20 min. hope it helped.

akbhaskar
Champ in-the-making
Champ in-the-making
Well I did not find way to override this problem so  org.alfresco.web.bean.users.TemplateMailHelperBean
this is the class, you can it is located inside of alfesco-web-client.jar, and you can just rebuld it( no need to rebuild all of the alfresco) .
 public void notifyUser(NodeRef person, NodeRef node, final String from, String roleText)
   {
      final String to = (String)this.getNodeService().getProperty(person, ContentModel.PROP_EMAIL);
     
      if (to != null && to.length() != 0)
      {
         String body = this.body;
         if (this.usingTemplate != null)
         {
            FacesContext fc = FacesContext.getCurrentInstance();
           
            // use template service to format the email
            NodeRef templateRef = new NodeRef(Repository.getStoreRef(), this.usingTemplate);
            ServiceRegistry services = Repository.getServiceRegistry(fc);
            Map<String, Object> model = DefaultModelHelper.buildDefaultModel(
                  services, Application.getCurrentUser(fc), templateRef);
            model.put("role", roleText);
            model.put("space", node);
            // object to allow client urls to be generated in emails
            model.put("url", new BaseTemplateContentServlet.URLHelper(fc));
           
            body = services.getTemplateService().processTemplate("freemarker", templateRef.toString(), model);
         }
         this.finalBody = body;
        
         MimeMessagePreparator mailPreparer = new MimeMessagePreparator()
         {
            public void prepare(MimeMessage mimeMessage) throws MessagingException
            {
               MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
               message.setTo(to);
               message.setSubject(subject);
               message.setText(finalBody,true); //HIRE IS THE CHANGE.
               message.setFrom(from);
            }
         };
        
         if (logger.isDebugEnabled())
            logger.debug("Sending notification email to: " + to + "\n…with subject:\n" + subject + "\n…with body:\n" + body);
        
         try
         {
            // Send the message
            this.getMailSender().send(mailPreparer);
         }
         catch (Throwable e)
         {
            // don't stop the action but let admins know email is not getting sent
            logger.error("Failed to send email to " + to, e);
         }
      }
   }

this would be in your case, because you are using notifying the users of space change. this change would not take more then 20 min. hope it helped.

Thank you very much. Will try this.