Java Mail attachment not shown in outlook

左心房为你撑大大i 提交于 2019-12-11 04:08:46

问题


we use Java Mail to send E-Mails with PDF attachments via SMTP over Lotus Notes to our customers. Some time ago we got notified that serveral customers don't received an attachment.

One of these customers uses Microsoft Outlook and got an attachment flag in his inbox. But when he opens the E-Mail, he doesn't see an attachment. We don't have the possibility to check the version of the E-Mail client's and to do customer side test's, because our customers are worldwide located.

If our customer responds or (internal) forward the E-Mail, the attachment shown in receiver's E-Mail client.

The following part is the affected Java source code:

private static Multipart createMultipartMailWithAttachment(String messageText)
        throws MessagingException {
    // Message with attachments
    Multipart mp = new MimeMultipart();

    // Attach Text
    MimeBodyPart mbp1 = new MimeBodyPart();
    mbp1.setText(messageText, UTF8, HTML);
    mp.addBodyPart(mbp1);

    for (File f : attachments) {
        MimeBodyPart fileAttachment = new MimeBodyPart();
        try {
            fileAttachment.setDisposition(MimeBodyPart.ATTACHMENT);
            fileAttachment.attachFile(f);
            if(f.getName().toLowerCase().endsWith(PDF_EXTENSION)) {
                fileAttachment.setHeader(CONTENT_TYPE, APPLICATION_PDF);
            }
        } catch (IOException e) {
            returnMessage = e.getMessage();
        }
        mp.addBodyPart(fileAttachment);
    }
    return mp;
}

We already tested different webmail services like gmail.com, yahoo.com and outlook.com. In every case the attachment was shown. Also in an local installation of Mozilla Thunderbird, Microsoft Outlook or Lotus Notes was the attachment shown.

After many inquiries we got many different solution processes. See setDisposition(MimeBodyPart.ATTACHMENT) and setHeader(CONTENT_TYPE, APPLICATION_PDF). None of these solutions lead us to success. Does anyone know a solution or a new solution process to solve that problem?


回答1:


We had a similar problem where we sent file attachments from a J2EE application to various mail accounts. We utilized SMTP gmail server (smtp.gmail.com) with port 465 and HTTPS connection type for our outgoing messages.

Attachments to the messages sent via Java were not shown in Outlook but we could observe them in web interface for gmail accounts.

In our case, it turned out to be that MimeMultipart construction was not the correct one. We had

Multipart multipart = new MimeMultipart("alternative");

When we modified it to

Multipart multipart = new MimeMultipart();

the attachments became visible.

Please also refer to the following resource for a full explanation.




回答2:


If messages sent from other mailers work properly and only messages sent from JavaMail fail, you'll need to examine the raw MIME content of the working and non-working messages to see what's different. You should be able to reproduce whatever content works using JavaMail.

There's lots of ways to access the raw MIME content of messages; let me know if you need help with that.

Obviously you'll need working and non-working examples messages with similar content to compare. If you have a repeatable test case - a message you can send to the same recipient multiple times and it fails every time - that would be most helpful.




回答3:


I wanted to add a comment (question), but don't have the required points.

It could be a filter on the customer side that blocks attachments. See if the customer is getting a mail with attachment (same pdf) when sending it via normal outlook.

Second possible cause is the size of the attachment is a problem for the customer.

Third possible cause is that I have noticed that when I set up a rule to automatically put messages into a different folder, i see a message saying:

Links and other functionality have been disabled in this message. To turn on that functionality, move this message to the Inbox. Outlook blocked access to the potentially unsafe attachments: xxxx.pdf

Maybe this customer has setup a rule similarly.



来源:https://stackoverflow.com/questions/27405511/java-mail-attachment-not-shown-in-outlook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!