Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Sending email in Jira fails with javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed

Giulio Cardillo February 23, 2015

Hi all,

I'm trying to send a mail in my plugin but I get the following exception:

 

... 29 more
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1177)
Caused by: javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;
at com.atlassian.mail.server.impl.SMTPMailServerImpl.sendWithMessageId(SMTPMailServerImpl.java:175)
boundary="----=_Part_0_1808366927.1424711131972"
... 29 more
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:896)
Caused by: javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;
at javax.activation.DataHandler.writeTo(DataHandler.java:317)
boundary="----=_Part_0_1808366927.1424711131972"
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1485)
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:896)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1773)
at javax.activation.DataHandler.writeTo(DataHandler.java:317)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1121)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1485)
... 30 more
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1773)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1121)
... 30 more

 

I have created a sample plugin with just 1 component in it which tries to send an email in the constructor (I won't do that in the real plugin, here is just to make it simple).

The pom.xml is:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.test</groupId>
    <artifactId>test-mail</artifactId>
    <version>1.0-SNAPSHOT</version>

    <organization>
        <name>Example Company</name>
        <url>http://www.example.com/</url>
    </organization>

    <name>test-mail</name>
    <description>This is the com.test:test-mail plugin for Atlassian JIRA.</description>
    <packaging>atlassian-plugin</packaging>

    <dependencies>
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-api</artifactId>
            <version>${jira.version}</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>maven-jira-plugin</artifactId>
                <version>${amps.version}</version>
                <extensions>true</extensions>
                <configuration>
                    <productVersion>${jira.version}</productVersion>
                    <productDataVersion>${jira.version}</productDataVersion>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <properties>
        <jira.version>6.3.14</jira.version>
        <amps.version>5.0.13</amps.version>
    </properties>

</project>

 

And the atlassian-plugin.xml is: 

<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2">
    <plugin-info>
        <description>${project.description}</description>
        <version>${project.version}</version>
        <vendor name="${project.organization.name}" url="${project.organization.url}" />
        <param name="plugin-icon">images/pluginIcon.png</param>
        <param name="plugin-logo">images/pluginLogo.png</param>
    </plugin-info>


    <component key="myPluginComponent" class="com.test.TestMailComponent"/>

</atlassian-plugin>

And the component class is:

 

package com.test;

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.mail.Email;
import com.atlassian.mail.server.SMTPMailServer;

import javax.mail.Multipart;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMultipart;

public class TestMailComponent {

    public TestMailComponent() throws Exception {

        SMTPMailServer smtpMailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer();

        if (smtpMailServer==null) return;

        Email email = new Email("jiratest@gmail.com");

        email.setSubject("test mail");
        email.setFrom(smtpMailServer.getDefaultFrom());
        Multipart multiPart = new MimeMultipart();
        MimeBodyPart body = new MimeBodyPart();
        body.setContent("<p><a href+'#'>this is a link</a></p>", "text/html");
        multiPart.addBodyPart(body);
        email.setMimeType("text/html");

        MimeBodyPart attachBody = new MimeBodyPart();
        attachBody.setText("test attachment");
        attachBody.setFileName("Attachment.txt");
        multiPart.addBodyPart(attachBody);
        email.setMultipart(multiPart);
        smtpMailServer.send(email);

    }


}

I am starting the server with the command:

 

atlas-run -e --jvmargs '-Datlassian.mail.senddisabled=false'

 

which enables the outgoing mail configuration that is disabled by default when running the server via atlas-run.

I have set the default smtp configuration in JIRA using my gmail account. I assume that the configuration is set properly because the test run via the "Test Connection" button succeeds.

After some research I found tha the issue should be that the javax.activation.ObjectDataContentHandler class tries to load the proper Mime class handler according to what is defined in the mailcap file available in the javax.mail jar, but it cannot load it because that jar is not in the current class loader.

The problem is that I don't understand what should I do to make it working.

Can you please help? 

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Marcin Dzióbek November 29, 2015

Hi all.

I know it was long time ago... but if someone still needs a solution for JIRA's plugin ...

In a very similar case (described by Giulio) I have used successfully this code:
 
...

// JIRA 6.3.14 - part of servlet code (part of doPost method):

// in case of javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;
Thread.currentThread().setContextClassLoader(javax.mail.Message.class.getClassLoader());

/*
* Here you can try:
* - the above code to send email with attachment using JIRA's default smtp server,
*
* - or standard code like SendAttachmentInEmail from here:
* http://www.tutorialspoint.com/javamail_api/javamail_api_send_email_with_attachment.htm
*/

...

By testing Giulo's code from servlet doGet or doPost (written for JIRA 6.3.14 running under JDK 1.7) i can reproduce his problem. But after adding setContextClassLoader it started to work. Here is my version:

public static void sendTestMail() throws MessagingException, MailException{


Thread.currentThread().setContextClassLoader(javax.mail.Message.class.getClassLoader());
		
		SMTPMailServer smtpMailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer();
		if (smtpMailServer==null) return;
		Email email = new Email("\changeThisAddress@gmail.com");
		
		email.setSubject("test mail");
		email.setFrom(smtpMailServer.getDefaultFrom());
		Multipart multiPart = new MimeMultipart();
		MimeBodyPart body = new MimeBodyPart();
		body.setContent("<p><a href+'#'>this is a link</a></p>", "text/html");
		multiPart.addBodyPart(body);
		email.setMimeType("text/html");
		
		MimeBodyPart attachBody = new MimeBodyPart();
		attachBody.setText("test attachment");
		attachBody.setFileName("Attachment.txt");
		multiPart.addBodyPart(attachBody);
		email.setMultipart(multiPart);
		smtpMailServer.send(email);
		
	}

 

 

 

 

 

davost August 25, 2016

Thanks it works for me

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 23, 2015

Try to use the mail queue as per this answer: https://answers.atlassian.com/questions/12159000

I do not have any problems sending multipart mime emails through gmail, using the mail queue.

Giulio Cardillo February 23, 2015

Thanks for the answer. I forgot to mention that with mail queue it works. But I need to make it working with immediate send.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 24, 2015

Do you have Service Desk installed?

Giulio Cardillo February 24, 2015

Nope

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 24, 2015
Giulio Cardillo February 24, 2015

I first tried to add the mailcaps manually: MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap(); mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html"); mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml"); mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain"); mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed"); mc.addMailcap("message/rfc822;; x-java-content- handler=com.sun.mail.handlers.message_rfc822"); but unsuccessfully, then I tried to set the context class loader with: Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); and again unsuccessfully. As I said, this is a clean environment running with atlas-run, so I don't understand why using the apis provided by jira doesn't work for some classloader issues.

TAGS
AUG Leaders

Atlassian Community Events