Skip to main content

SMTP transport extension for JAX-WS RI

Posted by jitu on May 6, 2007 at 8:05 PM PDT

jax-ws-commons: JAX-WS commons - SMTP transport for<br /> JAX-WS<br />

Finally, we (vivek,
and I) put together a SMTP transport for JAX-WS !! JAX-WS works with
various transports and it also provides plugin
extensions to write any custom transport. SMTP transport takes
advantage of these extensions. SMTP transport is implemented as a custom
transport using href="">Adapter
extension on the server side and href="">
on the client side.


For the communication to happen between "Me" and "You", there needs to
be two inboxes: "My Inbox" and "Your Inbox".  "Me" sends
request messages to "You" and expect responses in "My Inbox".
Similarly,  "You" sends response messages to "My Inbox" in
order to reach "Me".

style="border: 0px solid ; width: 691px; height: 255px;" alt=""

SMTP advantages

  • It is reachable. No server setup is necessary.
  • Great asynchrony. Server need not be there when
    client sends a request message.

Client-side Programming

You need jaxws-smtp.jar and JavaMail in
your classpath for this to work. Typical client code would like this:

public void testSmtp() {
    SMTPTransportTube.dump = true; // Enable logging

    SMTPFeature feature = new SMTPFeature("", "");
    feature.setPOP3("", "uid", "password");
    GreetingService proxy =
        new GreetingServiceService().getGreetingServicePort(feature);

    WSBindingProvider bp = (WSBindingProvider)bp;
    ... = proxy.sayHelloTo("...");

configures SMTPFeature with SMTP(sending) and POP3(receiving)
configuration. This feature is used to create proxy. Once the endpoint
address is set, then proxy can be used to invoke web service.

Server-side Configuration

JAX-WS SMTP extension can be used with href="">JAX-WS
Spring extension for more flexible configuration --- in
particular to expose the same endpoint as both HTTP and SMTP. See href="">the
sample application for the complete example of how to put
this all together by using Maven.

  xmlns:ws =""
" title="">


  <wsm:smtp service="#myservice" incoming="#in" outgoing="#out" />
  <wsm:pop3 id="in" host="pop3.Host" uid="uid" password="password" />
  <wsm:sender id="out" host="" from="server.from@com"/>

  <ws:service id="myservice">
      <bean class="greeter.GreetingService" />


Alternatively, you can also configure the srever side
programatically without Spring like href="">this.


  • We automated the testing using href="">mock javamail

We'll be showing a SMTP demo  (along with JSON demo!)
in our JavaOne session href="">TS-4948
"Unleashing the Power of JAX-WS RI: Spring, Stateful Web Services,
SMTP, and More", so mark your calendars accordingly ...