Search code examples
htmlemaildspace

HTML in DSpace messages


We like to add HTML-layout to eMail messages as send by DSpace.
Simple adding HTML-tags to one of the eMail templates as 'subscription' does not work.
I suppose we have to do some Java programming, but I have no idea where to start.
Does anyone of you has experience with HTML in DSpace eMails?


Solution

  • Adding HTML tags in the EMail can be done, but this requires some changes to the default EMail class.

    It consists of the following changes:

    • When setting the text on the actual message sent, an additional subType can be added (Check : https://github.com/DSpace/DSpace/blob/master/dspace-api/src/main/java/org/dspace/core/Email.java#L293). By default this takes a text and the charset, but has an additional "subType". Setting this to "html" enables the message to properly check for tags.
    • In the "EMail" class, you could add an additional "subType" variable which defaults to "plain" for example, and can be overwritten through a setter. (I'd refrain from simply setting it to html for every email template as the checking for existing tags might break other templates and also take some extra time).
    • The actual code that calls the "subscription" template can then create the mail and set the subtype properly.
    • See example images for the difference between the "plain" and "html" subtype.

      "plain" subtype vs "html" subtype