0

I have added image path in ClassPathResource in java. and My Images and velocity files are Stored in src/main/resources

this is my java Coding :

@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());

This is my Velocity file:

<html>
<head>
<meta charset="utf-8">
</head>
<body>
<img src='$smfile' alt="birthay img"  with="130" height="130" >
</body>
</html>

Email receive my local System is Perfect....but Other System mail receive images are not Found..

Xstian
  • 8,184
  • 10
  • 42
  • 72
villa
  • 73
  • 1
  • 1
  • 10
  • Is the file pointed to by `$smfile` local or is it a http URL? In first case, you must include a mime encoded version of the file content in the mail itself, and velocity should not be the best tool for that part... – Serge Ballesta Mar 23 '17 at 08:32
  • $smfile is my local path...how to add http URL – villa Mar 23 '17 at 08:51
  • You could copy the file to a public http server, and pass the URL. Alternatively, learn how to embed as mime an image used in a HTML mail with javamail. Googling for *javamail include image* gives some hints including [this SO post](http://stackoverflow.com/a/20978441/3545273) – Serge Ballesta Mar 23 '17 at 09:04
  • See also this [JavaMail FAQ entry](http://www.oracle.com/technetwork/java/javamail/faq/index.html#sendmpr). – Bill Shannon Mar 23 '17 at 17:31

0 Answers0