JDK-8043221 : Problem sending multipart mail with Java7 Update 55 after creating soapmessage
  • Type: Bug
  • Component: xml
  • Affected Version: 7u55
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2014-05-07
  • Updated: 2014-11-21
  • Resolved: 2014-05-29
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

EXTRA RELEVANT SYSTEM CONFIGURATION :
JavaMail version 1.5.2

A DESCRIPTION OF THE PROBLEM :
After creating  soapmessage and adding a attachementpart in separat method JavaMail send multipart without bodyparts. The Email contains only a subject.

REGRESSION.  Last worked in version 7u51


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.Properties;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.xml.soap.AttachmentPart;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;

public class Test {

    String host=null;
    String user="";
    String password=null;
    String from=null;
    String to=null;
       
    public static void main(String[] args) {
        Test t=new Test();
       
        t.user=    "user@mydomain.de";
        t.from=    "user@mydomain.de";
        t.to=    "user@mydomain.de";
        t.user=    "user@mydomain.de";       
        t.password="topsecret";
        t.host="mail.mydomain.de";
       
        t.sendMail();    //this works
        t.addSoapAttachement();
        t.sendMail();    //after addAttachmentPart to soapmessage it do not work
       
    }
   
    void addSoapAttachement(){
        try {
            MessageFactory messageFactory = MessageFactory.newInstance();
            SOAPMessage message = messageFactory.createMessage();
            AttachmentPart a = message.createAttachmentPart();
            a.setContentType("binary/octet-stream");                           
            message.addAttachmentPart(a);
        } catch (SOAPException e) {
            e.printStackTrace();
        }
    }
   
    void sendMail() {
       
        Properties props = new Properties();
        props.put("mail.smtp.host", host);        
        props.put("mail.smtp.auth", "true");
       
        Session session = Session.getInstance(props);
        session.setDebug(true);
       
        // Define message
        MimeMessage message = new MimeMessage(session);
        try {
            message.setFrom(new InternetAddress(from));
            message.addRecipients(Message.RecipientType.TO, to);
            message.setSubject("das ist ein multipart test");

            Multipart multipart = new MimeMultipart();

            BodyPart messageBodyPart1 = new MimeBodyPart();
            messageBodyPart1.setText("bitte auch diesen Content senden");
            multipart.addBodyPart(messageBodyPart1);
           
            BodyPart messageBodyPart2 = new MimeBodyPart();
            messageBodyPart2.setContent("<b>bitte</b> auch diesen Content senden<br>ciau", "text/html; charset=UTF-8");
            multipart.addBodyPart(messageBodyPart2);
       
            message.setContent(multipart);
           
            Transport tr = session.getTransport("smtp");
            tr.connect(host,user, password);
            tr.sendMessage(message,InternetAddress.parse(to));
            tr.close();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
---------- END SOURCE ----------


Comments
The issue is reproducible with 7u55 both 32 and 64 bit on Windows 7. I cannot reproduce it with 8u0 and 9-ea. Also the test case successfully sends messages with attachments if 7u51 is used.
15-05-2014