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:
- Update the following file with the name of your overriden transport class
- Add the file to the
/lib directory on all nodes - 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) - In the WAS admin console go to Resources -> Mail -> Mail Providers -> Built-in Mail Provider (Cell scope, first one) -> Protocol providers -> smtp
- Change the Class name to the name of your transport class e.g. example.smtp.transport.ExampleSMTPTransport
- Click OK, Save changes, sync nodes, restart all servers