Javascript 从本地路径将图像添加到电子邮件

Javascript 从本地路径将图像添加到电子邮件,javascript,string,spring,thymeleaf,email-attachments,Javascript,String,Spring,Thymeleaf,Email Attachments,如何使用服务器内部的路径添加要包含在通过Spring和Thymeleaf发送的电子邮件中的图像 这是我的控制器: final Map inlineResources=new HashMap(); Set folderPath=new TreeSet(); 用于(文件:文件){ …以前的一些代码() StringBuilder路径文件=新的StringBuilder(config.getFileCachePath()); pathFile.append(“/”).append(folder.ge

如何使用服务器内部的路径添加要包含在通过Spring和Thymeleaf发送的电子邮件中的图像

这是我的控制器:

final Map inlineResources=new HashMap();
Set folderPath=new TreeSet();
用于(文件:文件){
…以前的一些代码()
StringBuilder路径文件=新的StringBuilder(config.getFileCachePath());
pathFile.append(“/”).append(folder.getId()).append(“/”).append(certificateFile.getName());
添加(路径证书);
}
String folderPathString=StringUtils.collectionToCommaDelimitedString(folderPath);
inlineResources.put(“img1”,“template/email/img/myImg.png”);

inlineResources.put(“文件”、“文件夹路径”)此问题的解决方案是使用“文件:”:


可能
文件
不是公共文件?看起来您试图将StringBuilder放置到集合中,而不是字符串。在StringBuilder上调用toString()方法。您的pathCertificate类型为StringBuilder。尝试了这个
folderPath.add(pathCertificate.toString())?我尝试使用folderPath.add(pathCertificate.toString());但我也有同样的问题:发送电子邮件时出错[mail@mail.com]'org.springframework.mail.MailSendException:发送邮件时失败的邮件:javax.mail.MessaginException:IOException;嵌套异常为:java.io.FileNotFoundException:无法打开类路径资源[srv/dev/contents/fileCache/134/file.jpg],因为它不存在。我在我的服务器[srv/dev/contents/photo/134/file.jpg]上使用相同的路径加载,例如在家中可能的照片:
String pathImg = certificateFile.toString().replace('\\', '/'); inlineResources.put("img", "file:"+pathImg);