1

When we send an email from our tomcat server, implementing MimeMultiPart, it opens in most mail software just fine, e.g. Gmail, Outlook, & Android Mail. But when it is opened on Apple Mail, it automatically opens PDF and images, which is permanent in mobile(phone and tablet, as laptops can be changed in command).

This is how it is designed for Apple, as I have read in a couple of websites. The problem is, even the embedded, supposedly a hidden attachment, is also shown. This results in double image, as we call the embedded via html in the mail.

The image is a logo, so this gets emailed always. I was hoping that there is a different protocol I can use that also works well in Apple mail. I haven't seen a similar issue in the web, so I have hope that we are just using some different protocol.

    BodyPart messageBodyPart = new MimeBodyPart();
    String htmlText = message + "<img src=\"cid:image123\">";
    messageBodyPart.setContent(htmlText, "text/html; charset=UTF-8");

    MimeMultipart mp = new MimeMultipart("mixed");
    mp.addBodyPart(messageBodyPart);

    BodyPart imageBodyPart = new MimeBodyPart();
    String file = this.getClass().getClassLoader().getResource("images/Logo.gif").getFile();
    DataSource fds = new FileDataSource(file);
    imageBodyPart.setFileName("Logo.gif");
    imageBodyPart.setHeader("Content-ID","<image123>");
    imageBodyPart.setDisposition(Part.INLINE);

    mp.addBodyPart(imageBodyPart);

When I remove the HTML code, it still shows the attached image in Apple mail, however, It will not show completely in other email software.

Jared Teng
  • 311
  • 1
  • 5
  • 21

2 Answers2

0

I've seen this behaviour before as well, which I recall was due to a difference in the MIME header parsing logic on the iOS devices.

This other post (and corresponding answers) refers and should guide you towards a working solution: Problem sending multipart mail using ActionMailer

Good luck and please let us know how you get on.

Community
  • 1
  • 1
Kitebuggy
  • 89
  • 6
  • I thought nil was a special disposition... I'll try to make it null or blank I guess. – Jared Teng Mar 18 '16 at 10:25
  • Did not work, just leaving the disposition blank. It still worked fine in Gmail and Outlook. But IOS mail was not too stable, sometimes the logo would be in the middle of the text. I will look again to it on Monday, to make sure it does not default a value. – Jared Teng Mar 18 '16 at 15:27
0

Defect finally on its way to production. With slight variation in MIME structure to https://stackoverflow.com/a/23853079/4558510

What I did was to construct,

  • mixed +
    • related +
    • html
    • inline image
  • attachment
  • attachment

Leaving out alternative with attachments because somehow, in the time of writing, Yahoo online client was not displaying them. Sticking them in mixed worked fine.

Tested and works with,

  • Apple/IOS Mail (Tablet Ipad 2)
  • Outlook Windows 7 client
  • Outlook mobile (Android)
  • Gmail Web Client
  • Gmail mobile (Android)
  • Android mobile Email (Lollipop)
  • Yahoo web client
  • Yahoo mobile Email (Android)
  • Lotus Notes Windows 7 client

Note: Android used is Samsung Note 4 Lollipop.

Code:

    BodyPart messageBodyPart = new MimeBodyPart();
    String htmlText = message + "<img src=\"cid:image123\">";
    messageBodyPart.setContent(htmlText, "text/html; charset=UTF-8");

    MimeMultipart mpRelated = new MimeMultipart("relative");
    mpRelated.addBodyPart(messageBodyPart);

    BodyPart imageBodyPart = new MimeBodyPart();
    String file = this.getClass().getClassLoader().getResource("images/Logo.gif").getFile();
    DataSource fds = new FileDataSource(file);
    imageBodyPart.setFileName("Logo.gif");
    imageBodyPart.setHeader("Content-ID","<image123>");
    imageBodyPart.setDisposition(Part.INLINE);

    mpRelated.addBodyPart(imageBodyPart);

    MimeMultipart mpMixed = new MimeMultipart("mixed");
    //Nest Related into mixed
    BodyPart relatedInMixed = new MimeBodyPart();
    relatedInMixed.setContent(mpRelated);
    mpMixed.addBodyPart(relatedInMixed);

    //TODO Add attachement to mpMixed
Community
  • 1
  • 1
Jared Teng
  • 311
  • 1
  • 5
  • 21