Java Mail附件未显示在Outlook中 [英] Java Mail attachment not shown in outlook

查看:203
本文介绍了Java Mail附件未显示在Outlook中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用Java Mail在Lotus Notes上通过SMTP通过SMTP向客户发送带有PDF附件的电子邮件. 不久前,我们收到通知,服务器客户未收到附件.

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.

这些客户之一使用Microsoft Outlook并在其收件箱中获得了附件标志.但是当他打开 电子邮件,他没有看到附件.我们无法检查电子邮件客户端的版本 并进行客户方面的测试,因为我们的客户遍布全球.

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.

以下部分是受影响的Java源代码:

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;
}

我们已经测试了不同的Webmail服务,例如gmail.com,yahoo.com和Outlook.com.在每种情况下 显示了附件.同样在Mozilla Thunderbird,Microsoft Outlook或Lotus Notes的本地安装中 显示了附件.

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.

经过多次查询,我们得到了许多不同的解决方案流程.请参阅setDisposition(MimeBodyPart.ATTACHMENT)setHeader(CONTENT_TYPE, APPLICATION_PDF).这些解决方案均无法使我们成功.有人知道吗 解决方案还是新的解决方案来解决该问题?

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?

推荐答案

我们遇到了类似的问题,我们将文件附件从J2EE应用程序发送到各种邮件帐户.我们使用SMTP gmail服务器(smtp.gmail.com)的端口465和HTTPS连接类型作为外发邮件.

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.

通过Java发送的邮件附件未在Outlook中显示,但我们可以在Web界面中观察到Gmail帐户.

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

在我们的案例中,事实证明MimeMultipart的构造不是正确的构造.我们有

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

Multipart multipart = new MimeMultipart("alternative");

当我们将其修改为

Multipart multipart = new MimeMultipart();

附件变得可见.

也请参考以下资源以获取完整说明.

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

这篇关于Java Mail附件未显示在Outlook中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆