How to send notification emails with HTML content for WSO2 API Manager

Abhishek De Silva
2 min readJan 27, 2019

--

Are you here because you are unable to figure out how to send notification emails with HTML content? Yes, this is the blog for you.

First of all, please note that the current implementation of the WSO2 API Manager doesn’t render the HTML content (text/html) instead, it sends email notifications as plain text (text/plain). This is because it uses the Axis2 Client (org.apache.axis2.client) to send the emails and it is a limitation of the Axis2 Client.

But good news! I have built a simple email sending module (so you don’t have to ;)) which is capable of rendering the HTML content. This uses the javax.mail library and you can activate this using five simple steps for your WSO2 API Manager. So let’s get down to business.

  • Download the [3] jar file or you can build the project [1] to get the jar and copy it to <APIM_HOME>/repository/components/lib directory.
  • Replace the Identity.Mgt.Notification.Sending.Module.1=org.wso2.carbon.identity.mgt.mail.DefaultEmailSendingModule of the <APIM_HOME>/repository/conf/identity/identity-mgt.properties file with the following.
Identity.Mgt.Notification.Sending.Module.1=org.wso2.carbon.custom.email.HTMLEmailSendingModule
  • After configuring the <transportSender name=”mailto” class=”org.apache.axis2.transport.mail.MailTransportSender”> [2] in the <APIM_HOME>/repository/conf/axis2/axis2.xml file, add the <parameter name=”transport.mail.ContentType”>text/html</parameter>as an additiong paramter. Now your axis.xml <transportSender> should look like below.
<transportSender name="mailto" class="org.apache.axis2.transport.mail.MailTransportSender">
<parameter name="mail.smtp.host">smtp.gmail.com</parameter>
<parameter name="mail.smtp.port">587</parameter>
<parameter name="mail.smtp.starttls.enable">true</parameter>
<parameter name="mail.smtp.auth">true</parameter>
<parameter name="mail.smtp.user"><username>@gmail.com</parameter>
<parameter name="mail.smtp.password"><password></parameter>
<parameter name="mail.smtp.from"><username>@gmail.com</parameter>
<parameter name="transport.mail.ContentType">text/html</parameter>
</transportSender>
  • Enclose the HTML content of your <APIM_HOME>/repository/conf/email/email-admin-config.xml with the CDATA tag as follows.
<![CDATA[ HTML Content here ]]>
  • Add an email to the user’s profile who is in need of the notification email (e.g. Password Recovery). This could be done by an admin user. Please go to <Users and Roles> -> List -> Users -> User Profile through the Carbon Management Console and add the email as follows.

That’s it.

Couple of things to remember here. You can use this service for the Password Recovery option of the WSO2 API Manager.

And this service has been only tested for the following WSO2 API Managers.

  1. WSO2 API Manager 2.2.0
  2. WSO2 API Manager 2.6.0

I will soon test this on the other WSO2 API Managers soon, I promise.

So hope you guys had a good read. If you enjoyed it, please give it a clap.

Until next time!

[1] https://github.com/abhishekdesilva/custom-email-module

[2] https://docs.wso2.com/display/AM260/Identity+Management+for+the+API+Store

[3] https://drive.google.com/open?id=18EewXhsj044wW3Sq_wvKxGixJ51dq6Qg

Cheers.

--

--