javax.mail & OSGi

262 views
Skip to first unread message

Bryan Hunt

unread,
Mar 11, 2016, 2:09:19 PM3/11/16
to bndtool...@googlegroups.com
Does anyone have a working recipe for javax.mail?  The Eclipse Orbit repo has two versions of javax.mail: javax.mail and javax.mail.glassfish.  I have tried both.  If I use javax.mail, I get:

javax.mail.NoSuchProviderException: Unable to locate provider for protocol: smtp

And if I use javax.mail.glassfish, I get:

java.lang.ClassNotFoundException: javax.net.SocketFactory not found by javax.mail.glassfish [8]

I tried setting -runsystempackages: javax.net in my launch.bndrun, but that didn’t help.

In each case, I’m using javax.activation 1.1.0 from Eclipse Orbit.

Bryan

Peter Kriens

unread,
Mar 14, 2016, 7:05:18 AM3/14/16
to bndtool...@googlegroups.com
The only way I got this one to work was to embed javax.mail + activation in a bundle and then front it with a nice DS oriented service API. Not only alleviate this the myriad of class loading hacks in javax.mail, it also allows you to easily register an Email service that is already configured via Configuration Admin.

Of course if you really need the javax.mail API for code you cannot control then you’re out of luck.

Kind regards,

Peter Kriens




--
You received this message because you are subscribed to the Google Groups "bndtools-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bndtools-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bryan Hunt

unread,
Mar 14, 2016, 10:00:31 AM3/14/16
to bndtool...@googlegroups.com
Thanks for the suggestion Peter.  I went to download the latest javax.mail from Oracle and found that it is now an OSGi bundle, and it “just works”.  No activation jar required.  What a pleasant surprise!  BTW, I am wrapping it with a DS and metatype :)

Bryan

Peter Kriens

unread,
Mar 14, 2016, 10:15:57 AM3/14/16
to bndtool...@googlegroups.com
That is good to hear, it was painful at the time. What service API do you use for the wrapper? I would like to add one to the OSGi enRoute APIs (and then let it go through the OSGi specification process.)

Kind regards,

Peter Kriens

Bryan Hunt

unread,
Mar 14, 2016, 10:52:10 AM3/14/16
to bndtool...@googlegroups.com

Peter Kriens

unread,
Mar 14, 2016, 1:19:23 PM3/14/16
to bndtool...@googlegroups.com
Yup, similar :-) I’ve added a builder interface to access some lesser used features like BCC and other headers.

Sigh, should really find the time to edit such a service API to enRoute. I got the feeling lots of people are doing the same thing. :-(

Kind regards,

Peter Kriens

Paul Bakker

unread,
Mar 14, 2016, 1:41:08 PM3/14/16
to bndtool...@googlegroups.com
Peter, are you aware of http://amdatu.org/components/email.html?

Cheers,

Paul

Peter Kriens

unread,
Mar 14, 2016, 1:58:13 PM3/14/16
to bndtool...@googlegroups.com
I guess I should have been but I wasn’t. Interesting how you put the builder on the Message, good idea, makes it more distributable.

As said, we should have MUCH more of these services that all people that make real apps design :-( 

Kind regards,

Peter Kriens

Bryan Hunt

unread,
Mar 16, 2016, 11:45:44 AM3/16/16
to bndtool...@googlegroups.com
FYI, I just ran into the following error:

javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed


The fix is:

    public void sendMessage(Message message) throws MessagingException {
      ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
      Thread.currentThread().setContextClassLoader(Transport.class.getClassLoader());

      

      try
      {
        Transport.send(message);
      }
      finally
      {
        Thread.currentThread().setContextClassLoader(contextClassLoader);
      }
    }

Bryan
Reply all
Reply to author
Forward
0 new messages