Hi All,
I am trying to implement an email notification service with Quartz. To email part, I am using this example 22.3.1.2. Inline resources. So when I pass images in their absolute paths it works perfectly. The problem occurs when I try to use relative paths. Here is a snippet:
Here is the exception:Code:private void sendStatusReport(final ReportPack reportPack) { final MimeMessagePreparator preparator = new MimeMessagePreparator() { public void prepare(MimeMessage mimeMessage) throws Exception { final MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true); //... final String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "mail-templates/statusReport.html", getModel(reportPack)); messageHelper.setText(text, true); loadImages(messageHelper); } private void loadImages(MimeMessageHelper messageHelper) throws MessagingException, URISyntaxException, FileNotFoundException { messageHelper.addInline("table_header_left", ResourceUtils.getFile("file:/resources/image/table_header_left.png")); messageHelper.addInline("table_header_right", ResourceUtils.getFile("file:/resources/image/table_header_right.png")); messageHelper.addInline("icon_search", ResourceUtils.getFile("file:/resources/image/icon_search.png")); } }; this.mailSender.send(preparator); }
The problem throws when the email is meant to be sent. I have tried some other approaches like:Code:Failed message 1: javax.mail.MessagingException: IOException while sending message; nested exception is: java.io.FileNotFoundException: \resources\image\table_header_left.png (The system can not find the file path) at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:422) at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:342) at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:357) at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:346) at br.com.suntech.img.web.email.Mailer.sendStatusReport(Mailer.java:127) at br.com.suntech.img.web.email.Mailer.executeInternal(Mailer.java:69) at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86) at org.quartz.core.JobRunShell.run(JobRunShell.java:202) ... 1 more
But all fails. I have an enterprise app in this structure:Code:1. ResourceUtils.getFile("classpath:resources/image/table_header_left.png")); 2. ResourceUtils.getFile("classpath*:resources/image/table_header_left.png")); 3. ResourceUtils.getFile("/resources/image/table_header_left.png"));
The tests are performed with Glassfish. Has someone any clue, please?Code:- app_ear.ear - ... - app_web.war - ... - resources - ... - image - ... - table_header_left.png - table_header_right.png - icon_search.png
Best Regards,
Iktuz


Reply With Quote
