Example usage for javax.mail.internet MimeMultipart addBodyPart

List of usage examples for javax.mail.internet MimeMultipart addBodyPart

Introduction

In this page you can find the example usage for javax.mail.internet MimeMultipart addBodyPart.

Prototype

@Override
public synchronized void addBodyPart(BodyPart part, int index) throws MessagingException 

Source Link

Document

Adds a BodyPart at position index.

Usage

From source file:com.eviware.soapui.impl.wsdl.submit.filters.WsdlPackagingRequestFilter.java

/**
 * Creates root BodyPart containing message
 *//*  ww w .  j  ava  2s  . c o m*/

protected void initRootPart(WsdlRequest wsdlRequest, String requestContent, MimeMultipart mp, boolean isXOP)
        throws MessagingException {
    MimeBodyPart rootPart = new PreencodedMimeBodyPart(System.getProperty("soapui.bodypart.encoding", "8bit"));
    rootPart.setContentID(AttachmentUtils.ROOTPART_SOAPUI_ORG);
    mp.addBodyPart(rootPart, 0);

    DataHandler dataHandler = new DataHandler(new WsdlRequestDataSource(wsdlRequest, requestContent, isXOP));
    rootPart.setDataHandler(dataHandler);
}

From source file:com.eviware.soapui.impl.wsdl.submit.filters.HttpRequestFilter.java

protected void initRootPart(HttpRequestInterface<?> wsdlRequest, String requestContent, MimeMultipart mp)
        throws MessagingException {
    MimeBodyPart rootPart = new PreencodedMimeBodyPart("8bit");
    // rootPart.setContentID( AttachmentUtils.ROOTPART_SOAPUI_ORG );
    mp.addBodyPart(rootPart, 0);//from   w w  w  .  j av a2s  . c o  m

    DataHandler dataHandler = new DataHandler(new RestRequestDataSource(wsdlRequest, requestContent));
    rootPart.setDataHandler(dataHandler);
}

From source file:com.eviware.soapui.impl.support.AbstractMockResponse.java

private void initRootPart(String requestContent, MimeMultipart mp, boolean isXOP) throws MessagingException {
    MimeBodyPart rootPart = new PreencodedMimeBodyPart("8bit");
    rootPart.setContentID(AttachmentUtils.ROOTPART_SOAPUI_ORG);
    mp.addBodyPart(rootPart, 0);

    DataHandler dataHandler = new DataHandler(new MockResponseDataSource(this, requestContent, isXOP));
    rootPart.setDataHandler(dataHandler);
}

From source file:immf.MyHtmlEmail.java

/**
 * @throws EmailException EmailException
 * @throws MessagingException MessagingException
 *///from  w ww .  j a v a 2s.  c o  m
private void build() throws MessagingException, EmailException {
    MimeMultipart rootContainer = this.getContainer();
    MimeMultipart bodyEmbedsContainer = rootContainer;
    MimeMultipart bodyContainer = rootContainer;
    BodyPart msgHtml = null;
    BodyPart msgText = null;

    rootContainer.setSubType("mixed");

    // determine how to form multiparts of email

    if (StringUtils.isNotEmpty(this.html) && this.inlineEmbeds.size() > 0) {
        //If HTML body and embeds are used, create a related container and add it to the root container
        bodyEmbedsContainer = new MimeMultipart("related");
        bodyContainer = bodyEmbedsContainer;
        this.addPart(bodyEmbedsContainer, 0);

        //If TEXT body was specified, create a alternative container and add it to the embeds container
        if (StringUtils.isNotEmpty(this.text)) {
            bodyContainer = new MimeMultipart("alternative");
            BodyPart bodyPart = createBodyPart();
            try {
                bodyPart.setContent(bodyContainer);
                bodyEmbedsContainer.addBodyPart(bodyPart, 0);
            } catch (MessagingException me) {
                throw new EmailException(me);
            }
        }
    } else if (StringUtils.isNotEmpty(this.text) && StringUtils.isNotEmpty(this.html)) {
        //If both HTML and TEXT bodies are provided, create a alternative container and add it to the root container
        bodyContainer = new MimeMultipart("alternative");
        this.addPart(bodyContainer, 0);
    }

    if (StringUtils.isNotEmpty(this.html)) {
        msgHtml = new MimeBodyPart();
        bodyContainer.addBodyPart(msgHtml, 0);

        // apply default charset if one has been set
        if (StringUtils.isNotEmpty(this.charset)) {
            msgHtml.setContent(this.html, Email.TEXT_HTML + "; charset=" + this.charset);
        } else {
            msgHtml.setContent(this.html, Email.TEXT_HTML);
        }
        if (contentTransferEncoding != null) {
            msgHtml.setHeader("Content-Transfer-Encoding", contentTransferEncoding);
        }

        Iterator<InlineImage> iter = this.inlineEmbeds.values().iterator();
        while (iter.hasNext()) {
            InlineImage ii = (InlineImage) iter.next();
            bodyEmbedsContainer.addBodyPart(ii.getMbp());
        }
    }

    if (StringUtils.isNotEmpty(this.text)) {
        msgText = new MimeBodyPart();
        bodyContainer.addBodyPart(msgText, 0);

        // apply default charset if one has been set
        if (StringUtils.isNotEmpty(this.charset)) {
            msgText.setContent(this.text, Email.TEXT_PLAIN + "; charset=" + this.charset);
        } else {
            msgText.setContent(this.text, Email.TEXT_PLAIN);
        }
        if (contentTransferEncoding != null) {
            msgText.setHeader("Content-Transfer-Encoding", contentTransferEncoding);
        }
    }
}