Package javax.mail

Examples of javax.mail.BodyPart


        } catch (URISyntaxException ex) {
            ds = new URLDataSource(getClass().getResource("/log4j.properties"));
        }
        DataHandler dh = new DataHandler(ds);

        BodyPart attachmentBodyPart;
        // Create another body part
        attachmentBodyPart = new MimeBodyPart();
        // Set the data handler to the attachment
        attachmentBodyPart.setDataHandler(dh);
        // Set the filename
        attachmentBodyPart.setFileName(dh.getName());
        // Set Disposition
        attachmentBodyPart.setDisposition(Part.ATTACHMENT);

        mixed.addBodyPart(plainPart);
        mixed.addBodyPart(htmlPart);
        // Add attachmentBodyPart to multipart
        mixed.addBodyPart(attachmentBodyPart);
View Full Code Here


    public static String toString(Message message) throws MessagingException, IOException {
        Object content = message.getContent();
        if (content instanceof MimeMultipart) {
            MimeMultipart multipart = (MimeMultipart) content;
            if (multipart.getCount() > 0) {
                BodyPart part = multipart.getBodyPart(0);
                content = part.getContent();
            }
        }
        if (content != null) {
            return content.toString();
        }
View Full Code Here

     */
    @Converter
    public static String toString(Multipart multipart) throws MessagingException, IOException {
        int size = multipart.getCount();
        for (int i = 0; i < size; i++) {
            BodyPart part = multipart.getBodyPart(i);
            if (part.getContentType().startsWith("text")) {
                return part.getContent().toString();
            }
        }
        return null;
    }
View Full Code Here

                int count = container.getCount();
                getLogger().info("This part contains " + count + " parts.");
                parts = new SimpleMessageAttributes[count];
                for (int i = 0; i < count ; i ++) {
                    getLogger().info("Getting embedded part: " + i);
                    BodyPart nextPart = container.getBodyPart(i);

                    if (nextPart instanceof MimePart) {
                        SimpleMessageAttributes partAttrs = new SimpleMessageAttributes();
                        partAttrs.parseMimePart((MimePart)nextPart);
                        parts[i] = partAttrs;
View Full Code Here

            //If TEXT body was specified, create a alternative container and add it to the embeds container
            if (EmailUtils.isNotEmpty(this.text))
            {
                bodyContainer = new MimeMultipart("alternative");
                final BodyPart bodyPart = createBodyPart();
                try
                {
                    bodyPart.setContent(bodyContainer);
                    bodyEmbedsContainer.addBodyPart(bodyPart, 0);
                }
                catch (final MessagingException me)
                {
                    throw new EmailException(me);
View Full Code Here

     * @since 1.0
     */
    public Email addPart(final String partContent, final String partContentType)
        throws EmailException
    {
            final BodyPart bodyPart = createBodyPart();
        try
        {
            bodyPart.setContent(partContent, partContentType);
            getContainer().addBodyPart(bodyPart);
        }
        catch (final MessagingException me)
        {
            throw new EmailException(me);
View Full Code Here

     * @throws EmailException An error occurred while adding the part.
     * @since 1.0
     */
    public Email addPart(final MimeMultipart multipart, final int index) throws EmailException
    {
            final BodyPart bodyPart = createBodyPart();
        try
        {
            bodyPart.setContent(multipart);
            getContainer().addBodyPart(bodyPart, index);
        }
        catch (final MessagingException me)
        {
            throw new EmailException(me);
View Full Code Here

        {
            throw new EmailException("Invalid message supplied");
        }
        try
        {
            final BodyPart primary = getPrimaryBodyPart();

            if (primary instanceof MimePart && EmailUtils.isNotEmpty(charset))
            {
                ((MimePart) primary).setText(msg, charset);
            }
            else
            {
                primary.setText(msg);
            }
        }
        catch (final MessagingException me)
        {
            throw new EmailException(me);
View Full Code Here

            {
                // before a multipart message can be sent, we must make sure that
                // the content for the main body part was actually set.  If not,
                // an IOException will be thrown during super.send().

                final BodyPart body = this.getPrimaryBodyPart();
                try
                {
                    body.getContent();
                }
                catch (final IOException e) // NOPMD
                {
                    // do nothing here.
                    // content will be set to an empty string as a result.
View Full Code Here

    {
        if (EmailUtils.isEmpty(name))
        {
            name = ds.getName();
        }
        final BodyPart bodyPart = createBodyPart();
        try
        {
            bodyPart.setDisposition(disposition);
            bodyPart.setFileName(MimeUtility.encodeText(name));
            bodyPart.setDescription(description);
            bodyPart.setDataHandler(new DataHandler(ds));

            getContainer().addBodyPart(bodyPart);
        }
        catch (final UnsupportedEncodingException uee)
        {
View Full Code Here

TOP

Related Classes of javax.mail.BodyPart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.