You must be logged in to do that (write wiki)
Last updated October 29, 2008 15:22, by Ralph Soika
Feedicon  

With the Imixs JEE Mailplugin it is easy to send out mails during a workflow step. To use this Plugin in your Workflow Application you need to add the following PluginClass to the Model Configuration:

org.imixs.workflow.jee.plugins.MailPlugin

More details about this plugin and its configuration can be found here

How to perform additional Mail Lookup

In some cases it is possible that the mail server used by the configured mailsession did not accept simple usernames like the remote user name. The remoteuse name is typical used if you send a mail to current editor. And also for the sender (from attribute) the callerPrincipal will be used by the MailPlugin per default. If the mailserver did not accept the remote user name you will see an exception like this:

 com.sun.mail.smtp.SMTPSendFailedException
 remoteusername... Domain name required for sender address remoteusername at 
 com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1515) at 
 com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1054) at 
 com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:634) at javax.mail.Transport.send0(Transport.java:189) at 
 javax.mail.Transport.send(Transport.java:118) at org.imixs.workflow.jee.plugins.MailPlugin.close(MailPlugin.java:254) at 
 org.imixs.workflow.WorkflowKernel.closePlugins(WorkflowKernel.java:505)


To avoid this behavior you can easily subclass the MailPlugin and override the getInternetAddress Method. This method is responsible to transform a given name into a valid internet address used to send out an smtp message.

The following code shows an example of such a Subclass. The class uses the fetchEmail method to lookup a valid mail attribute in a provided ldap directory. The ldap directory is configured as a jndi ressource inside the glassfish server.


 package com.demo.util;
 
 import javax.mail.internet.AddressException;
 import javax.mail.internet.InternetAddress;
 import javax.naming.Context;
 import javax.naming.InitialContext; 
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.DirContext;
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 
 import org.imixs.workflow.jee.plugins.MailPlugin;
 
 public class DemoMailPlugin extends MailPlugin {
 
 	/**
 	 * this helper method fetches a mail attribute from a ldap directory 
 	 */
 	public InternetAddress getInternetAddress(String aAddr)
 			throws AddressException {
 
 		
 		// is smtp address?
 		if(aAddr.indexOf('@')>-1)
 			return super.getInternetAddress(aAddr);
 		
 		// try to get email from gd....
 		try {
 			aAddr=fetchEmail(aAddr);
 		} catch (NamingException e) {
 			// no valid email was found!
 			e.printStackTrace();
 		}
 		return new InternetAddress(aAddr);
 	}
 
 	private String fetchEmail(String user) throws NamingException {
 		Context initCtx = new InitialContext();
 		DirContext ldapCtx = (DirContext) initCtx
 				.lookup("com.demo.directory");
 		SearchControls ctls = new SearchControls();
 		ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
 		String searchfilter = "";
 		searchfilter = "(uid=" + user + ")";
 		NamingEnumeration answer = ldapCtx.search("", searchfilter, ctls);
 		if (answer.hasMore()) {
 			SearchResult entry = (SearchResult) answer.next();
 			Attributes attrs = entry.getAttributes();
 
 			// Attribute attr = null;
 
 			Attribute attr = attrs.get("mail");
 
 			if (attr != null)
 				return (String) attr.get(0);
 		}
 		return aQnummer;
 	}
  }


  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close