20 Replies Latest reply on Aug 31, 2016 6:46 AM by jeantags

    Adding email templates in plugin

    Novice

      I was wondering if there was a way to add e-mail templates using a plugin jar?  I'm looking at the templates defined in jive_clearspace_i18_en.xml.  I'd like to add one more to the list (specifically the template used for document expiration) using a plugin.  Is this even possible?

       

      I apologize if this has already been asked or is documented somewhere.

       

      Thanks!

      Eric

        • Re: Adding email templates in plugin
          Novice

          I ended up creating my own custom version of DocumentExpirationTask for my plugin.  I used the spring.xml to override the default one by including my own bean with id "documentExpirationTask".  My custom class doesn't rely on the e-mail templates.  I'd still like to know if there is a better way of doing this.  If anyone has any ideas, please let me know!

            • Re: Adding email templates in plugin
              mtodd Intermediate

              Ironic that I end up replying to your post, but this may help others as well. I created a file called mail_template_i18n_en_US.xml and ensured that it was placed in my plugins resources folder. The name of that file must begin with mail_template_ and must contain _i18n_ followed by the locale key (meaning that a filename like mail_template_test_asdfadsfds_i18n_en_US.xml would be valid). I haven't located a dtd, but this is the general format of the xml:

               

              <?xml version="1.0" encoding="UTF-8" ?>
              <message-templates>
                  <template name="my.template.name" displayName="Custom Template">
                      <description>A basic custom email template.</description>
                      <instructions>Just use it.</instructions>
                      <subject>
                          <![CDATA[Custom Email]]>
                      </subject>
                      <body>
                        <![CDATA[Hello ${SkinUtils.getDisplayName(user)}]]>
                      </body>
                  </template>
              </message-templates>
              

               

              I discovered this by reviewing the source to com.jivesoftware.base.plugin.configurators.EmailTemplateConfigurator. The elements under <template> should be pretty self explanitory, and you are allowed to include multiple <template> elements within that file.

               

              Message was edited by: Morgan Todd

                • Re: Adding email templates in plugin
                  kshaw79 Advanced

                  Just what I was looking for.  Thanks for sharing this.  Maybe someone from Jive could get this little nugget of info added to the official documentation.

                   

                  By the way, the template tag changed a bit.  I am not sure when, but this is what I use in 4.5.x.

                   

                  <?xml version="1.0" encoding="UTF-8"?>
                  <message-templates>
                            <template name="messagetemplatename.email" displayName="Message Template Name">
                                      <description>Description of this message template.</description>
                                      <bean>config.filename:beans/MessageTemplateNameJSON.properties</bean>
                                      <instructions><![CDATA[ The following tokens may be used as part of this email:<br /><br />
                  ${jiveURL}, ${userDisplayName}, ${username}, ${userID}, ${email}, ${requestIP} ]]></instructions>
                                      <subject><![CDATA[ Email message subject ]]></subject>
                                      <textBody>
                                                <![CDATA[ Hello, ${userDisplayName}. ]]>
                                      </textBody>
                                      <htmlBody>
                                                <![CDATA[Hello, <a href="${jiveURL}/people/${username}">${userDisplayName}</a>.]]>
                                      </htmlBody>
                            </template>
                  </message-templates>
                  

                   

                  The body tag has been split out into the textBody and htmlBody tags.  There is also a new bean tag.  The bean holds the values for the tokens to be used in the message template preview.  Here is a sample.

                   

                  {
                            "MessageTemplateNameBean": {
                                      "jiveURL" = "http://www.jivesoftware.com",
                                      "userDisplayName" = "John Smith",
                                      "username" = "jsmith",
                                      "userID" = "1234",
                                      "email" = "jsmith@example.com",
                                      "requestIP" = "127.0.0.1"
                            }
                  }
                  

                   

                  The file includes "JSON" in the filename, but it's not true JSON, so don't worry about those equal signs.  This is working for me.

                    • Re: Adding email templates in plugin
                      emile.senga Intermediate

                      I have created a template and named it mail_template_en_GB.xml

                       

                      in my plugin, I set the template properties like so:

                      message.setSubjectProperty("validation.email.custom.subject"); 
                      message.setHtmlBodyProperty("validation.email.custom.htmlBody");
                      

                       

                      and add required tokens like so:

                      message.getContext().put("verificationLink", verifyLink);
                      message.getContext().put("daysRemaining", this.getDaysRemaining());
                      

                       

                      I, however, keep getting the following error:

                       

                      02 Sep 2011 10:39:25,376 [Thread-9] [:] ERROR util.TemplateUtil - Trouble processing template with key validation.email.custom.htmlBody : Template validation.email.custom.htmlBody:en_GB not found.
                      java.io.FileNotFoundException: Template validation.email.custom.htmlBody:en_GB not found.
                                at freemarker.template.Configuration.getTemplate(Configuration.java:489)
                                at freemarker.template.Configuration.getTemplate(Configuration.java:452)
                                at com.jivesoftware.community.util.TemplateUtil.applyFreemarkerTemplate(TemplateUtil.java:133)
                                at com.jivesoftware.community.util.TemplateUtil.applyFreemarkerTemplate(TemplateUtil.java:115)
                                at com.jivesoftware.community.mail.outgoing.processor.pre.DefaultOutgoingMailProcessor.handle(DefaultOutgoingMailProcessor.java:73)
                                at com.jivesoftware.community.mail.outgoing.processor.OutgoingMailProcessorChain.preProcess(OutgoingMailProcessorChain.java:52)
                                at com.jivesoftware.community.impl.EmailSender.access$000(EmailSender.java:33)
                                at com.jivesoftware.community.impl.EmailSender$1.call(EmailSender.java:96)
                                at com.jivesoftware.community.impl.EmailSender$1.call(EmailSender.java:91)
                                at com.jivesoftware.community.aaa.authz.SystemExecutor.executeCallable(SystemExecutor.java:43)
                                at com.jivesoftware.community.impl.EmailSender.process(EmailSender.java:112)
                                at com.jivesoftware.community.impl.EmailSender.run(EmailSender.java:60)
                                at com.jivesoftware.community.impl.EmailManagerImpl$EmailHandlerThread.run(EmailManagerImpl.java:197)
                      02 Sep 2011 10:39:25,376 [Thread-11] [:] ERROR util.TemplateUtil - Trouble processing template with key validation.email.custom.htmlBody : Template validation.email.custom.htmlBody:en_GB not found.
                      java.io.FileNotFoundException: Template validation.email.custom.htmlBody:en_GB not found.
                                at freemarker.template.Configuration.getTemplate(Configuration.java:489)
                                at freemarker.template.Configuration.getTemplate(Configuration.java:452)
                                at com.jivesoftware.community.util.TemplateUtil.applyFreemarkerTemplate(TemplateUtil.java:133)
                                at com.jivesoftware.community.util.TemplateUtil.applyFreemarkerTemplate(TemplateUtil.java:115)
                                at com.jivesoftware.community.mail.outgoing.processor.pre.DefaultOutgoingMailProcessor.handle(DefaultOutgoingMailProcessor.java:73)
                                at com.jivesoftware.community.mail.outgoing.processor.OutgoingMailProcessorChain.preProcess(OutgoingMailProcessorChain.java:02 Sep 2011 10:41:30,705 [main] [:] WARN init - File logging online.
                      

                       

                      My mail_template doesn't seem to be getting picked up when I install it, any pointers to something I could be missing?

                        • Re: Adding email templates in plugin
                          Ryan Rutan Guru

                          Off the top of my head...your steps look fine.  Try this for the file name though.

                           

                          mail_templates_i18n_en_GB.xml and make sure the file is in the <plugin_root>/resources directory.  See if that helps.

                            • Re: Adding email templates in plugin
                              emile.senga Intermediate

                              Hi Ryan, I renamed the file and ensured it sits in <plugin_root>/resources, but still get the same issue. Did you, perhaps, find anything that alerts you to where I could be doing something wrong? When i rename my template to anything that's in jive_i18n_en.xml it seems to work but I would rather not alter any of the existing templates to get it working. Do you know of any ways to verify if the template is getting picked up?

                               

                              Thanks for the help, btw

                                • Re: Adding email templates in plugin
                                  emile.senga Intermediate

                                  Solved. I had placed the template files in the wrong 'resources' folder.

                                    • Re: Adding email templates in plugin
                                      Ryan Rutan Guru

                                      Glad you got it squared away. Sorry I wasn't more specific on that. =)

                                        • Re: Adding email templates in plugin
                                          Novice

                                          Hi,

                                          I was just wonderring, is it possible ot use the above techniques to override an existing mail template? I need to change the invite Others to Content email template to exclude the name of the content it is sharing, as well as changing the url it is sending (we need a URL for blogs that contains the blog ID instead of the blog post name)

                                           

                                          Thanks very much in advance for anyhelp with this

                                           

                                          Cheers,

                                          Laura

                                            • Re: Adding email templates in plugin
                                              cwmenke Novice

                                              To clarify a couple things:

                                               

                                              1. Put the mail_templates_i18n_en_US.xml in [your plugin]/src/main/plugin/resources
                                              2. You can override existing mail templates (you can copy the existing template from jive_i18n_en.xml)
                                                • Re: Adding email templates in plugin
                                                  Novice

                                                  Hi Kit,

                                                   

                                                  I understand this proces, overriding the xml, however - the problem I am facing, is that (Although the templates state that the ${blog} and ${blogPost}  full objects are able to be used in the template - they actually are not - and error out when i try and access them) I need access to the blog and blog post IDs to bulid a URL that does not contain the Blog subject/name.

                                                   

                                                  How would I go about getting access to these objects - or at the very least the ids of the blogs and blog posts?????

                                                  • Re: Adding email templates in plugin
                                                    chetanmahendru Advanced

                                                    Hey Ryan Rutan , Ryan King Brad Chesman ,

                                                     

                                                    I had done the above steps and was able to send the email in our UAT instance using the custom plugin I had developed. I deployed the same code today on our production instance and got the error, Can anyone of you let me know what can I do to fix this? We need this to be resolved as soon as possible as we need this to be available to the users in the next few hours

                                                     

                                                    2015-11-19 19:35:13,323 [Thread-30] [::] ERROR com.jivesoftware.community.mail.util.TemplateUtil - Trouble processing template with key sso.emails.update.textBody : Template sso.emails.update.textBody:en not found.

                                                    2015-11-19 19:35:13,342 [Thread-30] [::] ERROR com.jivesoftware.community.mail.util.TemplateUtil - Trouble processing template with key sso.emails.update.htmlBody : Template sso.emails.update.htmlBody:en not found.

                                                    2015-11-19 19:35:13,367 [Thread-30] [::] ERROR com.jivesoftware.community.mail.util.TemplateUtil - Trouble processing template with key sso.emails.update.subject : Template sso.emails.update.subject:en not found.

                                                    2015-11-19 19:35:13,368 [Thread-30] [::] ERROR com.jivesoftware.community.mail.outgoing.processor.pre.DefaultOutgoingMailProcessor - Could not determine an email string : key sso.emails.update.subject

                                                    2015-11-19 19:35:13,368 [Thread-30] [::] ERROR com.jivesoftware.community.mail.outgoing.processor.OutgoingMailProcessorChain - Could not determine an email string : key sso.emails.update.subject

                                                    java.lang.IllegalStateException: Could not determine an email string : key sso.emails.update.subject

                                                      at com.jivesoftware.community.mail.outgoing.processor.pre.DefaultOutgoingMailProcessor.handle(DefaultOutgoingMailProcessor.java:107)

                                                      at com.jivesoftware.community.mail.outgoing.processor.OutgoingMailProcessorChain.preProcess(OutgoingMailProcessorChain.java:53)

                                                      at com.jivesoftware.community.mail.outgoing.EmailSender.access$2(EmailSender.java:1)

                                                      at com.jivesoftware.community.mail.outgoing.EmailSender$2.call(EmailSender.java:179)

                                                      at com.jivesoftware.community.mail.outgoing.EmailSender$2.call(EmailSender.java:1)

                                                      at com.jivesoftware.community.aaa.authz.SystemExecutor.executeCallable(SystemExecutor.java:42)

                                                      at com.jivesoftware.community.mail.outgoing.EmailSender.processMessage(EmailSender.java:195)

                                                      at com.jivesoftware.community.mail.outgoing.EmailSender.access$0(EmailSender.java:164)

                                                      at com.jivesoftware.community.mail.outgoing.EmailSender$1$1.hasNext(EmailSender.java:130)

                                                      at com.jivesoftware.util.SmtpProxy.send(SmtpProxy.java:206)

                                                      at com.jivesoftware.community.mail.outgoing.EmailSender.run(EmailSender.java:77)

                                                      at com.jivesoftware.community.mail.outgoing.EmailManagerImpl$EmailHandlerThread.run(EmailManagerImpl.java:428)

                                                • Re: Adding email templates in plugin
                                                  Novice

                                                  Ryan Rutan has any of this changed in Jive 6 that you are aware of? We have a template (mail_template_i18n_en_US.xml) off the resources root (src/main/plugin/resources/) but Java is now throwing NullPointerException on retrieving the mail properties.

                                                    • Re: Adding email templates in plugin
                                                      Ryan Rutan Guru

                                                      To my knowledge no, have you tried with just en as the locale?  All the rest looks good to me, granted I've only used custom mail templates a few times.

                                                       

                                                      RR

                                                        • Re: Adding email templates in plugin
                                                          Novice

                                                          I did, unfortunately that doesn't work either. Is there any official documentation on sending emails from a plugin? This is definitely working in 4.5.6.2

                                                            • Re: Adding email templates in plugin
                                                              Novice

                                                              From the logs (the real email address is valid)

                                                              [INFO] [talledLocalContainer] 2013-08-02 11:44:51,095 [http-8080-5] [1:admin:REGULAR] INFO

                                                               

                                                              EmailMessage{recipients=[EmailAddress{email='david.ritsema@domain.com', name='David Ritsema'}],

                                                              sender=EmailAddress{email='jive6@localhost', name='Jive Dev'},

                                                              subjectProperty='featured.homepage.mail.subject',

                                                              textBodyProperty='featured.homepage.mail.textBody',

                                                              htmlBodyProperty='featured.homepage.mail.htmlBody',

                                                              textBody='null', htmlBody='null', subject='null', attachments=[], locale=null,

                                                              context={

                                                              featuredContentModeratorURL=http://localhost:8080/people/admin,

                                                              featuredContentModerator=ImmutableUser: 1 [admin] [david.ritsema@domain.com] ,

                                                              featuredContentModeratorName=David Ritsema,

                                                              featuredContent=[com.jive.featuredhomepage.SelectedFeaturedContentManagerImpl$1@4a3a0004]

                                                              }, includeHeaderAndFooter=true, shouldFreemarkerParse=true, bccSender=false}

                                                               

                                                              [INFO] [talledLocalContainer] 2013-08-02 11:44:51,102 [http-8080-5]

                                                              [1:admin:REGULAR] WARN org.directwebremoting.impl.DefaultRemoter - Method execution failed:

                                                              [INFO] [talledLocalContainer] java.lang.NullPointerException

                                                              That doesn't seem to pull in the property values from the mail template unless this is a java issue? On a side note, all other system generated emails are working fine.

                                        • Re: Adding email templates in plugin
                                          jeantags Novice

                                          Wondering if someone can help me.

                                          I want the digest email to contain any new content, comments, discussions etc. added to the site but I don't even know where to begin with the variables. It shouldn't take a developer to customize this.