Sending E-Mails with Confluence 7

Hi,

we’ve got a problem with sending e-mails via the mailserver with Confluence 7.
On confluence version 6.15.8 you could send an e-mail like this:

MailQueueItem mailQueueItem = new ConfluenceMailQueueItem(address, subject, body, MIME_TYPE_HTML);
try {
mailQueueItem.execute();
}
catch(Exception e){
e.printStackTrace();
}

Alternatively you could replace mailQueueItem.execute() with mailQueueItem.send() (which is deprecated).
In Confluence 7 mailQueueItem.execute() doesn’t work anymore because the method was inherited from the class com.atlassian.core.task.Task and mailQueueItem doesn’t extend that class anymore.
When using mailQueueItem.send() I get the following error:

java.util.ServiceConfigurationError: javax.mail.Provider: Provider com.sun.mail.imap.IMAPProvider not found
[INFO] [talledLocalContainer] at java.util.ServiceLoader.fail(ServiceLoader.java:239)
[INFO] [talledLocalContainer] at java.util.ServiceLoader.access$300(ServiceLoader.java:185)
[INFO] [talledLocalContainer] at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:372)
[INFO] [talledLocalContainer] at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
[INFO] [talledLocalContainer] at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
[INFO] [talledLocalContainer] at javax.mail.Session.getProviderByProtocol(Session.java:1017)
[INFO] [talledLocalContainer] at javax.mail.Session.getProvider(Session.java:542)
[INFO] [talledLocalContainer] at javax.mail.Session.getTransport(Session.java:744)
[INFO] [talledLocalContainer] at javax.mail.Session.getTransport(Session.java:725)
[INFO] [talledLocalContainer] at com.atlassian.confluence.jmx.JmxSMTPMailServer.doSendWithMessageIdSupport(JmxSMTPMailServer.java:97)
[INFO] [talledLocalContainer] at com.atlassian.confluence.jmx.JmxSMTPMailServer.send(JmxSMTPMailServer.java:79)
[INFO] [talledLocalContainer] at com.atlassian.confluence.mail.template.ConfluenceMailQueueItem.send(ConfluenceMailQueueItem.java:124)
[INFO] [talledLocalContainer] at com.atlassian.confluence.mail.template.ConfluenceMailQueueItem.send(ConfluenceMailQueueItem.java:85)
[INFO] [talledLocalContainer] at myClass.lambda$myMethod$455dc5de$1(myClass.java:31)
[INFO] [talledLocalContainer] at com.atlassian.core.task.AbstractTaskQueue.flush(AbstractTaskQueue.java:33)

Atlassian says it should work with:
taskManager.addTask(“mail”, () -> mailQueueItem.send()); (https://confluence.atlassian.com/doc/preparing-for-confluence-7-0-950280675.html?_ga=2.10079349.1381186704.1571645937-691748913.1561968548)

But when we then use taskManager.flush() to execute the task we get the same error.
The mail server works fine, when we try to send test e-mails.

Many thanks