如何图像嵌入速度电子邮件模板

时间:2017-03-23 07:46:24

标签: java spring spring-mvc javamail velocity

我在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>

电子邮件接收我的本地系统是完美的......但是找不到其他系统邮件接收图像..

0 个答案:

没有答案