Example usage for javax.mail.internet MimePart setContent

List of usage examples for javax.mail.internet MimePart setContent

Introduction

In this page you can find the example usage for javax.mail.internet MimePart setContent.

Prototype

public void setContent(Object obj, String type) throws MessagingException;

Source Link

Document

A convenience method for setting this part's content.

Usage

From source file:org.sakaiproject.kernel.messaging.email.EmailMessageListener.java

/**
 * Sets the content of the mime part using the content of the email message.
 *
 * @param mimePart//from  w  w  w .java  2s  .co m
 *          To where the content should be set.
 * @param email
 *          From where the content should be retrieved.
 * @throws IOException
 *           If the content is a URL and there is a problem opening a stream
 *           to it.
 * @throws MessagingException
 *           If there is a problem setting the content to the mime part.
 */
private void setContent(MimePart mimePart, Message email) throws IOException, MessagingException {
    Object content = null;
    if (email.isBodyText()) {
        content = email.getText();
    } else {
        URL url = email.getBody();
        URLConnection conn = url.openConnection();
        content = conn.getContent();
    }

    mimePart.setContent(content, email.getMimeType());
}