0

I am trying to send meeting invite using the Javamail. In multipart I am creating three mimebodypart, 1.HTML mail body part 2.Calendar Inivte Part 3.Signature Image part (this part is the problem )

but when I send the mail, the signature image part gets converted to AT00001.bin and shown instead of signature image.

The image is shown if I remove the calendar invite part from mail. After some research I came to know that the the attachment part must be the last in the mail so to avoid this file creation, but after doing so the problem continues.(as you can see in the mimebody addpart sequence)

The code part is as below:

        Multipart multipart = new MimeMultipart("mixed"); 
        BodyPart messageBodyPart = buildHtmlTextPart(); //html is read and added to the mail body part
        BodyPart calendarPart = buildCalendarPart();
        BodyPart signatureImagePart = buildSignatureImagePart(); //image is read and added as a content part of html.

        multipart.addBodyPart(messageBodyPart);
        multipart.addBodyPart(calendarPart);
        multipart.addBodyPart(signatureImagePart);

buildSignatureImagePart() is as below,

        MimeBodyPart signatureimagepart = new MimeBodyPart();
        DataSource fds = new FileDataSource(filePath); //filepath is image file location

        signatureimagepart.setDataHandler(new DataHandler(fds));
        signatureimagepart.setHeader("Content-ID", "<my-image-id>");

buildHtmlTextPart() is as below,

        MimeBodyPart descriptionPart = new MimeBodyPart();

        descriptionPart.setContent("<html><body><b>Test</b> email <img src='cid:my-image-id'></body></html>", "text/html; charset=utf-8");

Please tell me if i am doing something wrong in this to get the image part. Is there any other way to do the same?

1 Answers1

0

The structure of your message is wrong.

What you want is an outer maultipart/mixed, the first body part of which is a multipart/related, the second body part of which is the calendar attachment. The multipart/related has two parts - the html text and the signature image that it references.

Bill Shannon
  • 29,579
  • 6
  • 38
  • 40