我在java中的ClassPathResource
中添加了图像路径。和我的图像和速度文件存储在src / main / resources
这是我的java编码:
@Autowired
private JavaMailSender javamailsender;
@Autowired
private VelocityEngine velocityEngine;
MimeMessage msg = javamailsender.createMimeMessage();
MimeMessageHelper emailObject = new MimeMessageHelper(msg, true,"UTF-8");
emailObject.setTo("******");
emailObject.setFrom("******");
Object smileimage = new ClassPathResource("smiley.png");
File smfile = ((ClassPathResource) smileimage).getFile();
Map model = new HashMap();
model.put("smfile", smfile);
StringBuffer content = new StringBuffer();
content.append(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
"/velocity/Demo.vm", "UTF-8", model));
Multipart mp = new MimeMultipart("alternative");
BodyPart htmlPart = new MimeBodyPart();
htmlPart.setContent(content.toString(), "text/html");
mp.addBodyPart(htmlPart);
msg.setContent(mp);
javamailsender.send(emailObject.getMimeMessage());
这是我的Velocity文件:
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<img src='$smfile' alt="birthay img" with="130" height="130" >
</body>
</html>
电子邮件接收我的本地系统是完美的......但是找不到其他系统邮件接收图像..