List of usage examples for org.springframework.mail.javamail MimeMessageHelper addCc
public void addCc(String cc, String personal) throws MessagingException, UnsupportedEncodingException
From source file:com.enonic.cms.core.mail.AbstractSendMailService.java
public final void sendMail(AbstractMailTemplate template) { try {/* w w w.j a v a 2 s . com*/ MessageSettings settings = new MessageSettings(); setFromSettings(template, settings); settings.setBody(template.getBody()); final MimeMessageHelper message = createMessage(settings, template.isHtml() || !template.getAttachments().isEmpty()); message.setSubject(template.getSubject()); final Map<String, InputStream> attachments = template.getAttachments(); for (final Map.Entry<String, InputStream> attachment : attachments.entrySet()) { message.addAttachment(attachment.getKey(), new ByteArrayResource(IOUtils.toByteArray(attachment.getValue()))); } if (template.isHtml()) { message.setText("[You need html supported mail client to read this email]", template.getBody()); } else { message.setText(template.getBody()); } if (template.getMailRecipients().size() == 0) { this.log.info("No recipients specified, mail not sent."); } for (MailRecipient recipient : template.getMailRecipients()) { if (recipient.getEmail() != null) { final MailRecipientType type = recipient.getType(); switch (type) { case TO_RECIPIENT: message.addTo(recipient.getEmail(), recipient.getName()); break; case BCC_RECIPIENT: message.addBcc(recipient.getEmail(), recipient.getName()); break; case CC_RECIPIENT: message.addCc(recipient.getEmail(), recipient.getName()); break; default: throw new RuntimeException("Unknown recipient type: " + type); } } } sendMessage(message); } catch (Exception e) { this.log.error("Failed to send mail", e); } }