Registering custom SMTPTransport in Confluence
Asked by Heiko Mattes:

Hi,

I'm trying to register my own SMTPTransport-class in Confluence, so that I can do some custom actions when an outgoing E-Mail is about to be sent.

I already have a working library for Jira, that gets correctly registered and does the custom actions I want. Now I copied that over into a Confluence project, but it doesn't work there any longer. Whenever I try to send an email, an exception is thrown:

```
An error has occurred with sending the test email:
com.atlassian.mail.MailException: javax.mail.NoSuchProviderException: smtp
 at com.atlassian.confluence.jmx.JmxSMTPMailServer.doSendWithMessageIdSupport(JmxSMTPMailServer.java:120)
 at com.atlassian.confluence.jmx.JmxSMTPMailServer.send(JmxSMTPMailServer.java:79)
 at com.atlassian.confluence.admin.actions.mail.SendTestEmailAction.execute(SendTestEmailAction.java:57)
 at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:168)
 at com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:35)
 at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
 at com.atlassian.confluence.core.ConfluenceWorkflowInterceptor.intercept(ConfluenceWorkflowInterceptor.java:33)
 at com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:165)
 ... 245 more
Caused by: javax.mail.NoSuchProviderException: smtp
 at javax.mail.Session.getService(Session.java:798)
 at javax.mail.Session.getTransport(Session.java:720)
 at javax.mail.Session.getTransport(Session.java:660)
 at javax.mail.Session.getTransport(Session.java:640)
 at com.atlassian.confluence.jmx.JmxSMTPMailServer.doSendWithMessageIdSupport(JmxSMTPMailServer.java:97)
 ... 361 more
```

Now I'm wondering why the same approach works in Jira, but not in Confluence, as the registering of the class has nothing to do with either Jira and Confluence, but with the underlying web-server. I was trying it on Confluence version 6.4, but it also didn't work in a lower version which I tried previously.

Here is what I did:

I added both those files into the META-INF directory src/main/resources

File: javamail.address.map

```
rfc822=smtp
```

File: javamail.providers

```
protocol=smtp; type=transport; class=class.that.extends.SMTPTransport;
```

And exported it as a jar file and copied it into the confluence/webapp/WEB-INF/lib folder. But somehow, it isn't recognized there.

I also tried copying the folder into the tomcat8/lib folder. There, the registration works and my class is at least about to get loaded. This then fails because it can't find imported classes (like com.sun.mail.smtp.SMTPTransport which it is extending).

I've googled a bit for the above mentioned exception, but all I could find is about an activation-library that is missing, but that is only for Java version 1.5 or lower. And for good measures, I tried it anyway, and it didn't work either.

So, my question now is, what am I doing wrong? What does it need so my SMTPTransport class is correctly loaded in Confluence? I really hope someone can help me there.


Answers:
author: Heiko Mattes
body: Well, after lots of searching, I finally found that it was a simple NullPointerException in my Constructor. But thanks to the excpetion getting somehow swallowed and not showing up, it was the last place I was looking for.


Tags: email

smtp