【发布时间】:2017-06-26 06:49:32
【问题描述】:
我正在使用 Spring Boot 从 Java 发送 HTML 电子邮件。电子邮件包括带有我们公司图像标志的签名。它工作得很好。在 gmail 上。但在 MacOS 应用程序电子邮件中,徽标是作为附件发送的,而不是内联的。
代码中不相关的部分被替换为 ...
final Locale locale = ...;
final MimeMessage mail = javaMailSender.createMimeMessage();
MimeMessageHelper helper;
try {
helper = new MimeMessageHelper(mail, true, "UTF-8");
helper.setTo(...);
helper.setCc(...);
helper.setBcc(...);
helper.setFrom(...);
final String htmlContent = templateEngine.process(..., new Context(locale, ...));
helper.setText(htmlContent, true);
helper.addInline("myImg", new ClassPathResource(".../myImg.png"));
} catch (UnsupportedEncodingException | MessagingException e) {
throw new MailSendException(..., e);
}
javaMailSender.send(mail);
HTML 由 thymeleaf 生成,如下:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
...
<img src=".../myImg.png" th:src="'cid:' + ${'myImg'}" />
</body>
</html>
【问题讨论】:
标签: java image email spring-boot