Spring 弹簧&x2B;ThymileAF邮件模板-为什么将内联图像附加到电子邮件?

Spring 弹簧&x2B;ThymileAF邮件模板-为什么将内联图像附加到电子邮件?,spring,email,templates,thymeleaf,Spring,Email,Templates,Thymeleaf,我正在使用spring+thymeleaf发送电子邮件。我的邮件模板中很少有正确显示在电子邮件中的图像,但是我看到未使用的图像被附加到电子邮件的底部。我在html中有业务逻辑,它决定了要显示什么和不显示什么,所以有时候一些图像没有被使用,而是被附加。我怎样才能摆脱它们 有什么想法吗 以下是我如何在html中加载图像: <img src="cid:change-password" alt=""> 以下是我发送电子邮件的方式: public void sendUsingTempl

我正在使用spring+thymeleaf发送电子邮件。我的邮件模板中很少有正确显示在电子邮件中的图像,但是我看到未使用的图像被附加到电子邮件的底部。我在html中有业务逻辑,它决定了要显示什么和不显示什么,所以有时候一些图像没有被使用,而是被附加。我怎样才能摆脱它们

有什么想法吗

以下是我如何在html中加载图像:

<img src="cid:change-password" alt="">

以下是我发送电子邮件的方式:

 public void sendUsingTemplate(String fromEmail, String toEmail, String subject, String templateName, Map<String, Object> variables) {
        MimeMessage message = mailSender.createMimeMessage();
    try {
        MimeMessageHelper helper = new MimeMessageHelper(message, true);
        helper.setSubject(subject);

        final Context context = new Context(Locale.getDefault());
        variables.forEach((name, value) -> context.setVariable(name, value));

        String text = templateEngine.process(templateName, context);
        helper.setText(text, true);
        helper.setFrom(fromEmail);
        helper.setTo(toEmail);

        Map<String, String> inlineResources = mailTemplateResourcesProvider.getInlineResources(templateName);
        inlineResources.forEach((contentId, file) -> addInlineWithoutCheckedException(helper, contentId, file));

        mailSender.send(message);
    } catch (Exception e) {
        logger.error("Error sending mail using template", e);
    }
public void sendUsingTemplate(字符串fromEmail、字符串toEmail、字符串subject、字符串templateName、映射变量){
MimeMessage message=mailssender.createMimeMessage();
试一试{
mimessagehelper=新的mimessagehelper(消息,true);
helper.setSubject(subject);
最终上下文=新上下文(Locale.getDefault());
variables.forEach((名称,值)->context.setVariable(名称,值));
String text=templateEngine.process(templateName,context);
setText(text,true);
helper.setFrom(fromEmail);
helper.setTo(toEmail);
Map inlineResources=mailTemplateResourcesProvider.getInlineResources(templateName);
forEach((contentId,文件)->addInlineWithoutCheckedException(helper,contentId,文件));
发送(消息);
}捕获(例外e){
logger.error(“使用模板发送邮件时出错”,e);
}

除非用户明确允许,否则外部资源永远不会加载到电子邮件中。它会让外部服务器知道资源正在加载,这违反了隐私。好吧,未使用的图像怎么办?如果它们没有被使用,为什么要首先附加它们?这不是邮件客户端的工作决定“哦,这张图片没有在html中使用,我只是默默地删除它。”许多附加到电子邮件的图片从未被电子邮件的html引用,例如,“附加的是一张孩子们在营地的照片。”"。因为我根据动态信息渲染不同的内容。有时我渲染图像X,有时我不渲染。然后,要么跟踪渲染所需的资源,只附加正在使用的资源,要么附加所有资源,然后听天由命地发送不必要的内容。外部资源永远不会加载到电子邮件中,除非ess用户明确允许这种情况发生。它让外部服务器知道资源正在加载,这违反了隐私。好吧,未使用的图像呢?如果它们没有被使用,为什么要首先附加它们?邮件客户端的工作不是决定“哦,这个图像没有在html中使用,我只是默默地删除它”。许多附加到电子邮件的图像从未被电子邮件的html引用,例如,“附加的是孩子们在营地的照片”。因为我根据动态信息渲染不同的内容。有时我渲染图像X,有时我不渲染。然后要么跟踪渲染所需的资源,只附加正在使用的资源,要么附加所有资源,然后听天由命地发送不必要的内容。