当然,我想知道如何设置freemarker模板或将要发送的消息的标题.
当我查看我在收件箱中每隔一段时间收到的MIME格式的邮件多部分邮件的来源时,这就是其中的内容:
This is a multi-part message in MIME format.------=_NextPart_000_B10D_01CBAAA8.F29DB300Content-Type: text/plainContent-transfer-encoding: 7bit...Text here...------=_NextPart_000_B10D_01CBAAA8.F29DB300Content-Type: text/HTML;charset="iso-8859-1"Content-transfer-encoding: quoted-printable<HTML><body> HTML code here ... </body></HTML>解决方法 如果发现任何不一致之处,请告诉我.我不得不从相当复杂的对象中提取它,这就是为什么它看起来像这样.
//some important importsimport freemarker.template.Template;import org.springframework.mail.javamail.*;import org.springframework.context.*;import org.springframework.web.servlet.vIEw.freemarker.FreeMarkerConfigurer;import javax.mail.internet.MimeMessage;private JavaMailSender mailSender;private MessageSource messageSource;private ExecutorService executor = Executors.newFixedThreadPool(50);MimeMessagePreparator preparator = new MimeMessagePreparator() { public voID prepare(MimeMessage mimeMessage) throws Exception { MimeMessageHelper message = new MimeMessageHelper(mimeMessage); message.setFrom(from); message.setTo(recipIEnt); message.setSubject(subject); // Now the message body. Multipart mp = new MimeMultipart(); BodyPart textPart = new MimeBodyPart(); Template textTemplate = freemarkerConfig.getConfiguration().getTemplate(textEmailTemplate); // "/WEB-INF/emailText/*.ftl" final StringWriter textWriter = new StringWriter(); textEmailTemplate.process(modelMap,textWriter); textPart.setText(textWriter.toString()); // sets type to "text/plain" BodyPart pixPart = new MimeBodyPart(); Template pixTemplate = freemarkerConfig.getConfiguration().getTemplate(pixEmailTemplate); // "/WEB-INF/emailPix/*.ftl" final StringWriter pixWriter = new StringWriter(); textEmailTemplate.process(modelMap,pixWriter); pixPart.setContent(pixWriter.toString(),"text/HTML"); // Collect the Parts into the MultiPart mp.addBodyPart(textPart); mp.addBodyPart(pixPart); // Put the MultiPart into the Message message.setContent(mp); }};executor.submit(new SendMail(preparator));class SendMail extends Thread { MimeMessagePreparator preparator; SendMail(MimeMessagePreparator preparator) { this.preparator = preparator; } public voID run() { mailSender.send(preparator); }}总结
以上是内存溢出为你收集整理的html – 通过Spring 3 JavaMail以MIME格式Freemarker模板创建多部分消息全部内容,希望文章能够帮你解决html – 通过Spring 3 JavaMail以MIME格式Freemarker模板创建多部分消息所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)