/ Published in: Java

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
throws MailerException { final boolean isHtml = BooleanUtils.toBooleanDefaultIfNull(html, false); final boolean multipart = attach != null && attach.size() > 0; MimeMessagePreparator preparator = new MimeMessagePreparator() { MimeMessageHelper messageHelper = new MimeMessageHelper( mimeMessage, multipart, "UTF-8"); messageHelper.setSubject(subject); messageHelper.setTo(toAddress); if (!StringUtils.isEmpty(cc)) { messageHelper.setCc(cc.split(",")); } // messageHelper.setBcc(bccEmail); messageHelper.setFrom(fromAddress); messageHelper.setText(body, isHtml); if (attach != null) { messageHelper.addAttachment(entry.getKey(), entry .getValue()); } } } }; try { this.mailSender.send(preparator); } catch (MailException e) { log.error("Error while sending mail", e); throw new MailException("Unable to send mail because of a unknown error, please try again", e); } }
Comments
