This document provides guidelines on how to configure Axis2 in order to get the mail transport working.
<transportSender name="mailto" class="org.apache.axis2.transport.mail.MailTransportSender"> <parameter name="mail.smtp.host">hostname</parameter> <parameter name="mail.smtp.user">username</parameter> <parameter name="transport.mail.smtp.password">password</parameter> </transportSender>
<transportReceiver name="mailto" class="org.apache.axis2.transport.mail.SimpleMailListener"> <parameter name="mail.pop3.host">mailhost</parameter> <parameter name="mail.pop3.user">username</parameter> <parameter name="mail.store.protocol">pop3</parameter> <parameter name="transport.mail.pop3.password">password</parameter> <parameter name="transport.mail.replyToAddress">server_emailaddress</parameter> <parameter name="transport.listener.interval">3000</parameter> </transportReceiver>
<transportSender name="mailto" class="org.apache.axis2.transport.mail.MailTransportSender"> <parameter name="mail.smtp.host">hostname</parameter> <parameter name="mail.smtp.user">username</parameter> <parameter name="transport.mail.smtp.password">password</parameter> <parameter name="mail.smtp.from">client_email_address</parameter> </transportSender>
<transportReceiver name="mailto" class="org.apache.axis2.transport.mail.SimpleMailListener"> <parameter name="mail.pop3.host">mailhost</parameter> <parameter name="mail.pop3.user">username</parameter> <parameter name="mail.store.protocol">pop3</parameter> <parameter name="transport.mail.pop3.password">password</parameter> <parameter name="transport.mail.replyToAddress">client_emailaddress</parameter> <parameter name="transport.listener.interval">3000</parameter> </transportReceiver>
private static EndpointReference targetEPR = new EndpointReference( "mailto:test@mail.com?x-service-path=/axis2/services/SampleService");
... ConfigurationContext ct = ConfigurationContextFactory.createConfigurationContextFromFileSystem( repository_path, axis2.xml_path); ServiceClient sender = new ServiceClient(ct, null); Options options = new Options(); options.setTo(targetEPR); options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI); options.setProperty(AddressingConstants.WS_ADDRESSING_VERSION, AddressingConstants.Final.WSA_NAMESPACE); options.setAction("urn:SampleService"); sender.setOptions(options); sender.engageModule("addressing"); ...
... Properties props = new Properties(); props.put("mail.smtp.user", "address@gmail.com"); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "465"); props.put("mail.smtp.starttls.enable","true"); props.put("mail.smtp.auth", "true"); //props.put("mail.smtp.debug", "true"); // if the user wants props.put("mail.smtp.socketFactory.port", "465"); props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.socketFactory.fallback", "false"); props.put("transport.mail.smtp.password", "password"); //then set the Properties object in the Option object. options.set(org.apache.axis2.transport.mail.Constants.MAILTO, props); ...
Please note that according to the mail transport specification, only SOAP 1.2 is supported.
For a non-SSL connection, as an example, the mail Listener can be activated by adding the following entry to the server axis2.xml file.(or look for and uncomment the section)
<transportReceiver name="mailto" class="org.apache.axis2.transport.mail.SimpleMailListener"> <parameter name="mail.pop3.host">hostname</parameter> <parameter name="mail.pop3.user">username</parameter> <parameter name="mail.store.protocol">pop3</parameter> <parameter name="transport.mail.pop3.password">password</parameter> <parameter name="transport.mail.replyToAddress">email_address</parameter> <parameter name="transport.listener.interval">3000</parameter> </transportReceiver>
Note: The @name="transport.mail.replyToAddress" is an important parameter. It supplies the Endpoint reference to the listener.
For an advanced user, this can be set to an SSL connection. For example, let's use this transport listener to pop from a specified gmail account.
<transportReceiver name="mailto" class="org.apache.axis2.transport.mail.SimpleMailListener"> <parameter name="mail.pop3.host">pop.gmail.com</parameter> <parameter name="mail.pop3.user">address@gmail.com</parameter> <parameter name="mail.pop3.socketFactory.class">javax.net.ssl.SSLSocketFactory</parameter> <parameter name="mail.pop3.socketFactory.fallback">false</parameter> <parameter name="mail.pop3.port">995</parameter> <parameter name="mail.pop3.socketFactory.port">995</parameter> <parameter name="transport.mail.pop3.password">password</parameter> <parameter name="transport.mail.replyToAddress">address@gmail.com</parameter> </transportReceiver>
If the Mail Listener is to be started as a standalone mail listener, it can be done with the following command with the all the Axis2 jars and the mail dependency jars in the classpath.
java org.apache.axis2.transport.mail.SimpleMailListener repository-directory
The following code segment shows how to send a one-way (IN-Only MEP) SOAP message using the mail transport. This needs the Transport Sender to be configured.
OMElement payload = .... String targetEPR = "mailto:user@mailhost.com?x-service-path=/axis2/services/Foo"; ConfigurationContext configurationContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(repo, axis2XML_location); ServiceClient servicClient = new ServiceClient(configurationContext, null); Options options = new Options(); options.setTo(targetEPR); options.setTransportInProtocol(Constants.TRANSPORT_MAIL); options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI); options.setProperty(AddressingConstants.WS_ADDRESSING_VERSION, AddressingConstants.Final.WSA_NAMESPACE); options.setAction("urn:SampleService"); servicClient.setOptions(options); sender.engageModule("addressing"); servicClient.fireAndForget(payload);
For further reading, please refer to Axis2 Mail Transport document.
Download Apache James and start James. Connect to the James server via Telnet as administrator James using the following code:
$telnet 127.0.0.1 4555 Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'. JAMES Remote Administration Tool 2.2.0 Please enter your login and password Login id: root Password: root Welcome root. HELP for a list of commands
Add users to James
adduser axis2-server axis2 User axis2-server added adduser axis2-client axis2 User axis2-client added Connection closed by foreign host.
Now James is up and running with the accounts.
The inbuilt mail server can be started from the command line using the following command when all the necessary JARS are in the class path.
java org.apache.axis2.transport.mail.server.MailServer
The server itself does not need any configuration or tinkering to work. A ConfigurationContext and the ports to operate on are the only details needed. The server will store the mails in the memory against the recipient till the recipient pops it from the server. To facilitate the use in Linux environments as a non root user, the POP and SMTP ports used by default configuration/test cases are, 1024, 25 and 1024, 110 respectively.