fb
info@yenlo.com
WSO2 Identity Server 2 min

WSO2TORIAL: Using tenant specific SMTP settings for Email service

sidharth
Sidharth Dash
Integration Specialist
email

When we create a multi-tenant environment in any of the WSO2 product a lot of tenant specific configurations are available and some of them not. That’s were Yenlo comes to the rescue!

In this blog I will concentrate on making email SMTP settings tenant specific in Identity Server and how it effects the end user. However, this approach can be applied to any of the WSO2 products.

Prerequisite:

  • Creating multiple tenants as described here.
  • Configuring different E-Mail templates for different tenant as described here.
  • Configuring user account locking and disabling as described here.

Problem:

When we change axis2.xml parameters there is no specification about the tenant. If one user from tenant1 another from tenant2 locks their account than they will receive E-Mail from a single user account. To make it tenant specific first we have to modify existing axis2.xml and then write custom code.

My Approach:

1. Modifying <CARBON_HOME>/repository/conf/axis2/axis2.xml

Add for each tenant name a new transportSender configuration. Just like this sample.

<transportSender name="tenant1.com" class="org.apache.axis2.transport.mail.MailTransportSender">

<parameter name="mail.smtp.from">admin@tenant1.com</parameter>

<parameter name="mail.smtp.user">tenant1user</parameter>

<parameter name="mail.smtp.password">password</parameter>

<parameter name="mail.smtp.host">smtp.tenant1.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.tenant">tenant1.com</parameter>

</transportSender>

<transportSender name="tenant2.com"class="org.apache.axis2.transport.mail.MailTransportSender">

<parameter name="mail.smtp.from">admin@tenant2.com</parameter>

<parameter name="mail.smtp.user">tenant2user</parameter>

<parameter name="mail.smtp.password">password</parameter>

<parameter name="mail.smtp.host">smtp.tenant2.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.tenant">tenant2.com</parameter>

</transportSender>

2. Modifying

<CARBON_HOME>/repository/conf/identity/identity-mgt.properties

Replace:

identity.Mgt.Notification.Sending.Module.1=org.wso2.carbon.identity.mgt.mail.DefaultEmailSendingModule

with

Identity.Mgt.Notification.Sending.Module.1=com.yenlo.identity.mgt.mail.TenentEmailSendingModule

3. We added this new as a pre-build JAR to the blog.

yenlo.identity.mgt.mail.TenentEmailSendingModule class

Add this .jar to:

 <CARBON_HOME>/repository/components/dropins/

and restart the server to deploy.

What this class will do:

  1. Check which tenant the current user belongs to;
  2. Get the SMTP configuration of this specific tenant;
  3. If the tenant email configuration for a tenant is not found in your AXIS2.xml file it will use the default email configuration.

When we set up multi-tenant environment we want to modify every bit of product to be it tenant specific. Following this tutorial you are able to use tenant specific SMTP configurations.

eng
Close
We appreciate it
Care to share

Please select one of the social media platforms below to share this pages content with the world