简体   繁体   English

gmail 为何显示使用通过 Amazon SES 发送的 MimeMessageHelper addInline 附加的图像的“无名”附件?

[英]How come gmail is showing 'noname' attachments for images attached using MimeMessageHelper addInline sent with Amazon SES?

When using Spring MimeMessageHelper to attach the icons using addInLine and sending with SES, some of the icons appear as 'noname' attachments.当使用 Spring MimeMessageHelper 使用 addInLine 附加图标并使用 SES 发送时,一些图标显示为“无名”附件。 These images seem to be random unused images from the same folder.这些图像似乎是同一文件夹中随机未使用的图像。

AddInLine code AddInLine 代码

    private void attachIconsInEmailBody(MimeMessageHelper messageHelper, String iconsPath) throws IOException,  MessagingException {
        Resource[] resources = resourcePatternResolver.getResources("classpath:" + iconsPath + "*.*");
        for (Resource attRes: resources) {
            String iconName = attRes.getFilename();
            messageHelper.addInline(iconName.split("\\.")[0], attRes);
        }

Email code Email代码

            MimeMessage message = new MimeMessage(session);
            MimeMessageHelper messageHelper = new MimeMessageHelper(message, true, "UTF-8");
            messageHelper.setFrom(new InternetAddress(emailObject.getSender()));
            messageHelper.setTo(InternetAddress.parse(emailObject.getRecipients()));
            messageHelper.setSubject(emailObject.getSubject());
            messageHelper.setText(htmlBody, true);
            messageHelper.setSentDate(new Date(System.currentTimeMillis()));

            // add all the icons in-line to display in the email body
            attachIconsInEmailBody(messageHelper,"static/logo/SG/");

Sendmail code:发送邮件代码:

            // send the email using the sendRawEmail API
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            message.writeTo(outputStream);
            RawMessage rawMessage = new RawMessage(ByteBuffer.wrap(outputStream.toByteArray()));
            SendRawEmailRequest rawEmailRequest = new SendRawEmailRequest(rawMessage);
            SendRawEmailResult emailResult = sesClient.sendRawEmail(rawEmailRequest);

            // set the response back in the email object for any further recon
            emailObject.setEmailResult(emailResult);
            outputStream.close();
            return emailResult;

Parts of html code: html部分代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
                                <td style="width: 40px; height: 120px;"><img
                                        src="cid:strauss_sg_blank1" style="height: 120px; width: 40px;"
                                        alt="strauss_sg_blank1">
                                </td>

                        <td valign="top"
                            style="width: 40px; height: 30px; background: #ffffff;"><img
                                src="cid:strauss_sg_blank2" style="height: 30px"
                                alt="strauss_sg_blank2"></td>
</body>
</html>

Logo Folder:徽标文件夹:

在此处输入图像描述

Email attachments: Email 附件: 在此处输入图像描述

I know it's a bit late to answer this question.我知道现在回答这个问题有点晚了。 I recently also experienced this issue while sending email using AWS SES.我最近在使用 AWS SES 发送 email 时也遇到了这个问题。 The reason is that the MimeMessageHelper does not set the filename for our inline images when it creates BodyPart from our images.原因是MimeMessageHelper在从我们的图像创建BodyPart时没有为我们的内联图像设置文件名。 The contentId it uses is twisted a bit with the prefix < and suffix > .它使用的contentId带有前缀<和后缀> We may retrieve the corresponding BodyPart instance from the helper class by the following code:我们可以通过以下代码从帮助程序 class 中检索相应的BodyPart实例:

private void attachIconsInEmailBody(MimeMessageHelper messageHelper, String iconsPath) throws IOException,  MessagingException {
        Resource[] resources = resourcePatternResolver.getResources("classpath:" + iconsPath + "*.*");
        for (Resource attRes: resources) {
            String iconName = attRes.getFilename();
            String contentId = iconName.split("\\.")[0];
            messageHelper.addInline(contentId , attRes);
            messageHelper.getMimeMultipart().getBodyPart("<" + contentId + ">").setFileName(iconName);

        }
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 阻止gmail将内嵌图像显示为附件 - Prevent gmail from showing inline images as attachments 春季:附件的MimeMessageHelper编码 - Spring: MimeMessageHelper encoding for attachments MimeMessageHelper 无法使用 JavaMail 发送同一文件的两个附件? - MimeMessageHelper not able to send two attachments of the same file using JavaMail? 如何阻止电子邮件中的嵌入图像被 GMail 显示为附件? - How to stop embedded images in email being displayed as attachments by GMail? 带有附件的Apache commons-mail HtmlEmail:在Gmail中html作为noname.html附加html - Apache commons-mail HtmlEmail with attachment: html is attached as noname.html in Gmail 使用意图时如何将附件加载到 gmail? - How do I get attachments loaded to gmail when using an intent? 对于从 java 程序发送的 email,html 内容中的 png 图像未显示在 gmail 客户端上 - png images in html content are not showing up on gmail client for the email sent from java program 使用smtp java通过Amazon SES发送电子邮件 - Send email with Amazon SES using smtp java 使用Amazon SES的简单Web服务 - Simple web service using Amazon SES 无法使用Java中的Amazon SES发送电子邮件 - Not able to send Email using Amazon SES in Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM