Example usage for org.springframework.mail.javamail MimeMessageHelper MimeMessageHelper

List of usage examples for org.springframework.mail.javamail MimeMessageHelper MimeMessageHelper

Introduction

In this page you can find the example usage for org.springframework.mail.javamail MimeMessageHelper MimeMessageHelper.

Prototype

public MimeMessageHelper(MimeMessage mimeMessage, int multipartMode) throws MessagingException 

Source Link

Document

Create a new MimeMessageHelper for the given MimeMessage, in multipart mode (supporting alternative texts, inline elements and attachments) if requested.

Usage

From source file:ubic.gemma.util.MailEngineImpl.java

/**
 * Convenience method for sending messages with attachments.
 * /* w ww.  j  a v a 2  s.c  o m*/
 * @param emailAddresses
 * @param resource to be attached
 * @param bodyText
 * @param subject
 * @param attachmentName
 * @throws MessagingException
 * @author Ben Gill
 */
@Override
public void sendMessage(String[] emailAddresses, ClassPathResource resource, String bodyText, String subject,
        String attachmentName) throws MessagingException {
    MimeMessage message = ((JavaMailSenderImpl) mailSender).createMimeMessage();

    // use the true flag to indicate you need a multipart message
    MimeMessageHelper helper = new MimeMessageHelper(message, true);

    helper.setTo(emailAddresses);
    helper.setText(bodyText);
    helper.setSubject(subject);

    helper.addAttachment(attachmentName, resource);

    ((JavaMailSenderImpl) mailSender).send(message);
}