微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

gmail 怎么会显示使用 MimeMessageHelper addInline 附加的图像的“noname”附件?

如何解决gmail 怎么会显示使用 MimeMessageHelper addInline 附加的图像的“noname”附件?

当使用 Spring MimeMessageHelper 通过 addInLine 附加图标并使用 SES 发送时,一些图标显示为“noname”附件。 这些图像似乎是同一文件夹中随机未使用的图像。

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

电子邮件代码

            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/");

发送邮件代码

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

部分 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>

标志文件夹:

enter image description here

电子邮件附件:

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。