Thursday, March 10, 2011

Controlling Emails Sent by Lotus Connections

View Comments
I’ve heard several times the need to customize or control how emails are sent by Lotus Connections. In one example, there was a need to blacklist certain users so that they wouldn’t receive an email notification.

The general pattern for influencing how emails may be delivered is to override the default SMTP transport with your own version that inspects the message and makes any modifications before it is sent ( you can modify the actual message, the recipients that it's going to be sent to, etc). In this instance, the transport would look at all the recipient email addresses and remove any blacklisted ones. How it determines what is blacklisted could be done in any number of ways (e.g. members of a community, an LDAP group, a CSV file, etc).

Here is a skeleton of the overridden transport class:
package example.smtp.transport;


import javax.mail.Address;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.SendFailedException;
import javax.mail.Session;
import javax.mail.URLName;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import com.sun.mail.smtp.SMTPTransport;


public class ExampleSMTPTransport
extends SMTPTransport {


public EESMTPTransport(Session session, URLName urlName) {


super(session, urlName);
 }


/**
 * Override the default sendMessage so that we can modify the outgoing
 * email message as we need.
 *
 */
 @Override
 public synchronized void sendMessage(Message message, Address[] recipients)
   throws MessagingException, SendFailedException {
   // Modify the message here…
   // This will send it
   super.sendMessage(message, recipients);
 }
}

So how do we get this installed? Here's the general process:
  1. Update the following file with the name of your overriden transport class
  2. Add the file to the /lib directory on all nodes
  3. Create a javamail.providers file in /java/jre/lib . The file should contain a single line: "protocol=smtp; type=transport; class=example.smtp.transport.ExampleSMTPTransport" (without quotes)
  4. In the WAS admin console go to Resources -> Mail -> Mail Providers -> Built-in Mail Provider (Cell scope, first one) -> Protocol providers -> smtp
  5. Change the Class name to the name of your transport class e.g. example.smtp.transport.ExampleSMTPTransport
  6. Click OK, Save changes, sync nodes, restart all servers
Enjoy!
blog comments powered by Disqus