Hi :)
I am trying to send an email with a plugin and i get the following exception:
com.atlassian.mail.MailException: javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory]
the problematic code is
private SMTPMailServer getServer() { List<SMTPMailServer> mailServers = mailServerManager .getSmtpMailServers(); for (SMTPMailServer mailServer : mailServers) { if (mailServer.getName().equalsIgnoreCase("Gmail server")) { return mailServer; } } return null; } @Override public void sendDirectEmail(Email email) throws MailException { SMTPMailServer mailServer = getServer(); email.setFrom(CONF_EMAIL); email.setFromName("[confluence]: NO-REPLY"); email.setMimeType("text/html"); mailServer.send(email); //here }
where gmail server is configured through jndi.
and declared in the atlassian-plugin.xml as
<component key="custom-email-service-impl" class="com.example.confluence.emailNotifier.components.CustomEmailServiceImpl" name="Custom Mail Service Impl" i18n-name-key="custom-email-service-impl.name"> <description key="custom-mail-service-impl.description">The Custom Eail Service Impl Plugin </description> <interface>com.example.confluence.emailNotifier.components.CustomEmailService </interface> </component> <component-import key="task-manager" interface="com.atlassian.core.task.MultiQueueTaskManager" filter="" /> </atlassian-plugin>
Any ideas why this exception is thrown?
I can only assume that for some reason context of jndi mapping is not fetched. And that is weird since another plugin executing the same exactly code throws no exception.Community moderators have prevented the ability to post new answers.
Where is this code called from ? This might be related to wrong classloader if you call the code from a REST service for example.
it comes from a
<component name="Comment Listener" class="com.example.confluence.emailNotifier.listeners.CommentsListener" key="commentListener" />
and the class' constructor looks like
private CustomEmailService service; public CommentsListener(EventPublisher eventPublisher, PageManager pageManager, BandanaManager bandanaManager, GroupManager groupManager, UserAccessor ua, MailServerManager msManager, MultiQueueTaskManager taskManager) { this.eventPublisher = eventPublisher; eventPublisher.register(this); this.pageManager = pageManager; this.bandanaManager = bandanaManager; this.groupManager = groupManager; this.ua = ua; emailRecipients = new HashSet<String>(); service = new CustomEmailServiceImpl(taskManager, msManager); }
and a simple system.err.println of mailServer.getJndiLocation() returns java:comp/env/mail/Session
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.