Example usage for javax.mail BodyPart setDisposition

List of usage examples for javax.mail BodyPart setDisposition

Introduction

In this page you can find the example usage for javax.mail BodyPart setDisposition.

Prototype

public void setDisposition(String disposition) throws MessagingException;

Source Link

Document

Set the disposition of this part.

Usage

From source file:sk.lazyman.gizmo.web.app.PageEmail.java

private Message buildMail(Session session) throws MessagingException, IOException {
    String subject = createSubject();
    Message mimeMessage = createMimeMessage(session, subject);
    mimeMessage.setDisposition(MimeMessage.INLINE);
    Multipart mp = new MimeMultipart("alternative");

    MimeBodyPart textBp = new MimeBodyPart();
    textBp.setDisposition(MimeMessage.INLINE);
    textBp.setContent("Please use mail client with HTML support.", "text/plain; charset=utf-8");
    mp.addBodyPart(textBp);//ww  w .  j  a v a  2 s . c  o m

    Multipart commentMultipart = null;
    EmailDto dto = model.getObject();
    if (StringUtils.isNotEmpty(dto.getBody())) {
        BodyPart bodyPart = new MimeBodyPart();
        bodyPart.setDisposition(MimeMessage.INLINE);
        DataHandler dataHandler = new DataHandler(
                new ByteArrayDataSource(dto.getBody(), "text/plain; charset=utf-8"));
        bodyPart.setDataHandler(dataHandler);

        commentMultipart = new MimeMultipart("mixed");
        commentMultipart.addBodyPart(bodyPart);
    }

    String html = createHtml();
    Multipart htmlMp = createHtmlPart(html);

    BodyPart htmlBp = new MimeBodyPart();
    htmlBp.setDisposition(BodyPart.INLINE);
    htmlBp.setContent(htmlMp);
    if (commentMultipart == null) {
        mp.addBodyPart(htmlBp);
    } else {
        commentMultipart.addBodyPart(htmlBp);
        BodyPart all = new MimeBodyPart();
        all.setDisposition(BodyPart.INLINE);
        all.setContent(commentMultipart);
        mp.addBodyPart(all);
    }
    mimeMessage.setContent(mp);

    return mimeMessage;
}

From source file:sk.lazyman.gizmo.web.app.PageEmail.java

private Multipart createHtmlPart(String html) throws IOException, MessagingException {
    Multipart multipart = new MimeMultipart("related");

    BodyPart bodyPart = new MimeBodyPart();
    bodyPart.setDisposition(MimeMessage.INLINE);
    DataHandler dataHandler = new DataHandler(new ByteArrayDataSource(html, "text/html; charset=utf-8"));
    bodyPart.setDataHandler(dataHandler);
    multipart.addBodyPart(bodyPart);/*ww w.j  a v  a 2  s.c  o  m*/

    return multipart;
}