为什么gmail会显示“noname”附件,用于使用amazonses发送的mimessagehelper addinline附加的图片?

mitkmikd  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(624)

当使用spring mimessagehelper通过addinline和ses发送来附加图标时,一些图标显示为“noname”附件。这些图像似乎是来自同一文件夹的随机未使用的图像。
附加线路代码

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>

徽标文件夹:

电子邮件附件:

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题