Package javax.mail.internet

Examples of javax.mail.internet.MimeMultipart


    private MimeMultipart createMixedMultipartAttachments(MailConfiguration configuration, Exchange exchange)
        throws MessagingException, IOException {

        // fill the body with text
        MimeMultipart multipart = new MimeMultipart();
        multipart.setSubType("mixed");
        addBodyToMultipart(configuration, multipart, exchange);
        String partDisposition = configuration.isUseInlineAttachments() ? Part.INLINE : Part.ATTACHMENT;
        if (exchange.getIn().hasAttachments()) {
            addAttachmentsToMultipart(multipart, partDisposition, exchange);
        }
View Full Code Here


    }

    protected void createMultipartAlternativeMessage(MimeMessage mimeMessage, MailConfiguration configuration, Exchange exchange)
        throws MessagingException, IOException {

        MimeMultipart multipartAlternative = new MimeMultipart("alternative");
        mimeMessage.setContent(multipartAlternative);

        MimeBodyPart plainText = new MimeBodyPart();
        plainText.setText(getAlternativeBody(configuration, exchange), determineCharSet(configuration, exchange));
        // remove the header with the alternative mail now that we got it
        // otherwise it might end up twice in the mail reader
        exchange.getIn().removeHeader(configuration.getAlternativeBodyHeader());
        multipartAlternative.addBodyPart(plainText);

        // if there are no attachments, add the body to the same mulitpart message
        if (!exchange.getIn().hasAttachments()) {
            addBodyToMultipart(configuration, multipartAlternative, exchange);
        } else {
            // if there are attachments, but they aren't set to be inline, add them to
            // treat them as normal. It will append a multipart-mixed with the attachments and the body text
            if (!configuration.isUseInlineAttachments()) {
                BodyPart mixedAttachments = new MimeBodyPart();
                mixedAttachments.setContent(createMixedMultipartAttachments(configuration, exchange));
                multipartAlternative.addBodyPart(mixedAttachments);
            } else {
                // if the attachments are set to be inline, attach them as inline attachments
                MimeMultipart multipartRelated = new MimeMultipart("related");
                BodyPart related = new MimeBodyPart();

                related.setContent(multipartRelated);
                multipartAlternative.addBodyPart(related);
View Full Code Here

        }


        try {
            //Create the message body
            MimeMultipart multipart = new MimeMultipart();
            //Add message as the first mime body part
            MimeBodyPart part = new MimeBodyPart();
            part.setContent(sout.toString(), "text/plain");
            part.setHeader(RFC2822Headers.CONTENT_TYPE, "text/plain");
            multipart.addBodyPart(part);

            //Add the original message as the second mime body part
            part = new MimeBodyPart();
            part.setContent(message.getContent(), message.getContentType());
            part.setHeader(RFC2822Headers.CONTENT_TYPE, message.getContentType());
            multipart.addBodyPart(part);

            //if set, attach the full stack trace
            if (attachStackTrace && mail.getErrorMessage() != null) {
                part = new MimeBodyPart();
                part.setContent(mail.getErrorMessage(), "text/plain");
                part.setHeader(RFC2822Headers.CONTENT_TYPE, "text/plain");
                multipart.addBodyPart(part);
            }

            reply.setContent(multipart);
            reply.setHeader(RFC2822Headers.CONTENT_TYPE, multipart.getContentType());
        } catch (IOException ioe) {
            throw new MailetException("Unable to create multipart body");
        }

        //Create the list of recipients in our MailAddress format
View Full Code Here

                    break;
                default:
                case NONE: //NONE:
                    break;
            }
            MimeMultipart multipart = new MimeMultipart();
            //Add message as the first mime body part
            MimeBodyPart part       = new MimeBodyPart();
            part.setText(sout.toString());
            part.setDisposition("inline");
            multipart.addBodyPart(part);
            if(getAttachmentType() != NONE) {
                part = new MimeBodyPart();
                switch(getAttachmentType()) {
                    case HEADS: //HEADS:
                        part.setText(head);
                        break;
                    case BODY: //BODY:
                        try {
                            part.setText(message.getContent().toString());
                        } catch(Exception e) {
                            part.setText("body unavailable");
                        }
                        break;
                    case ALL: //ALL:
                        StringBuffer textBuffer =
                            new StringBuffer(1024)
                                .append(head)
                                .append("\n\n")
                                .append(message.toString());
                        part.setText(textBuffer.toString());
                        break;
                    case MESSAGE: //MESSAGE:
                        part.setContent(message, "message/rfc822");
                        break;
                }
                part.setDisposition("Attachment");
                multipart.addBodyPart(part);
            }
            reply.setContent(multipart);
            reply.setHeader(RFC2822Headers.CONTENT_TYPE, multipart.getContentType());
            reply.setRecipients(Message.RecipientType.TO, apparentlyTo);
        } else {
            // if we need the original, create a copy of this message to redirect
            reply = getPassThrough() ? new MimeMessage(message) : message;
            if (isDebug) {
View Full Code Here

            if (message.isMimeType("text/plain")) {
                //This is a straight text message... just append the single part normally
                addToText(message);
            } else if (message.isMimeType("multipart/mixed")) {
                //Find the first body part, and determine what to do then.
                MimeMultipart multipart = (MimeMultipart)message.getContent();
                MimeBodyPart part = (MimeBodyPart)multipart.getBodyPart(0);
                attachFooter(part);
                //We have to do this because of a bug in JavaMail (ref id 4404733)
                message.setContent(multipart);
            } else if (message.isMimeType("multipart/alternative")) {
                //Find the HTML and text message types and add to each
                MimeMultipart multipart = (MimeMultipart)message.getContent();
                for (int i = 0; i < multipart.getCount(); i++) {
                    MimeBodyPart part = (MimeBodyPart)multipart.getBodyPart(i);
                    attachFooter(part);
                }
                //We have to do this because of a bug in JavaMail (ref id 4404733)
                message.setContent(multipart);
            } else {
View Full Code Here

      throws MimeParserException
  {
    Assert.notNull(this.mimeMessage, "No message was processed. Initialize first.");
    message.getPart(partId); // make sure that part exists, otherwise IAE will be thrown

    MimeMultipart mp;
    Object content;
    InputStream in = null;

    // find based on Part ID eg. 1.2.3
    try {
      mp = (MimeMultipart) this.mimeMessage.getContent();
      String[] partNums = partId.split("\\.");

      // loop through parts to reach the final part
      for (int i = 0; i < partNums.length; i++)
      {
        int localPartId = Integer.parseInt(partNums[i]) - 1;
        content = mp.getBodyPart(localPartId).getContent();

        if (content instanceof MimeMultipart) {
          mp = (MimeMultipart) content;
        } else if ((content instanceof String)
            || (content instanceof InputStream)
            || (content instanceof MimeMessage)) {
          in = mp.getBodyPart(localPartId).getInputStream();
        } else {
          // normally, we should never get here
          // perhaps bad Part ID
          throw new MessagingException("MIME part not found");
        }
View Full Code Here

        } else {
          textBody.append((String) content);
        }
      }
    } else if (content instanceof MimeMultipart) {
      MimeMultipart multipart = (MimeMultipart) content;

      for (int i = 0; i <  multipart.getCount(); i++)
      {
        // build next part id
        StringBuilder nextPartId = new StringBuilder(partId);

        // add period if not at root level
        if (!partId.isEmpty())
          nextPartId.append(".");

        int localPartId = i+1; // IMAPv4 MIME part counter starts from 1
        nextPartId.append(localPartId);

        Part nextPart = multipart.getBodyPart(i);
        parseMessagePart(nextPart, nextPartId.toString());
      }
    } else if ((content instanceof InputStream)
        || (content instanceof MimeMessage)) {
      // binary, message/rfc822 or text attachment
View Full Code Here

        addresses[toIndex++] = new InternetAddress(t);
      }
      msg.setRecipients(Message.RecipientType.TO, addresses);
      msg.setSubject(subject);
      msg.setSentDate(new Date());
      final Multipart mp = new MimeMultipart();
      final MimeBodyPart mbp1 = new MimeBodyPart();
      mbp1.setText(message);
      mp.addBodyPart(mbp1);
      if (paths != null && paths.length > 0) {
        for (final Path path : paths) {
          final MimeBodyPart mbp = new MimeBodyPart();
          final FileDataSource fds = new FileDataSource(path.toFile());
          mbp.setDataHandler(new DataHandler(fds));
          mbp.setFileName(fds.getName());
          mp.addBodyPart(mbp);
        }
      }
      // text attachment
      // MimeBodyPart mbp2 = new MimeBodyPart();
      // mbp2.setText("some text in an attachment form");
View Full Code Here

        for (int i = 0; i < recipients.length; i++) {
            addressTo[i] = new InternetAddress(recipients[i]);
        }
        //msg.setRecipients(Message.RecipientType.BCC, addressTo);
  
        MimeMultipart multipart = new MimeMultipart("alternative");
       
        if(attachmentURL!=null) {
          MimeBodyPart filePart = new MimeBodyPart();
          filePart.setFileName( attachmentFileName );
         
      URL url = new URL(attachmentURL);
      URLConnection connection = url.openConnection();
      connection.setRequestProperty( "User-Agent","OpenForum");
         
          ByteArrayDataSource ds = new ByteArrayDataSource(connection.getInputStream(), attachmentMimeType);
          filePart.setDataHandler(new DataHandler(ds));
          multipart.addBodyPart(filePart);
        }
       
        MimeBodyPart textPart = new MimeBodyPart();
        textPart.setContent(textMessage, "text/plain");
        multipart.addBodyPart(textPart);
       
        if(htmlMessage!=null) {
          MimeBodyPart htmlPart = new MimeBodyPart();
          String htmlData = htmlMessage;
          htmlPart.setContent(htmlData, "text/html");
          multipart.addBodyPart(htmlPart);
        }
       
        // Setting the Subject and Content Type
        msg.setSubject(subject);
        msg.setContent(multipart);
View Full Code Here

            MimeBodyPart htmlPart = new MimeBodyPart();
            htmlPart.setText(html);
            htmlPart.addHeaderLine("Content-Type: text/html; charset=\"" + CHARSET + "\"");
            htmlPart.addHeaderLine("Content-Transfer-Encoding: quoted-printable");

            Multipart content = new MimeMultipart("alternative");
            content.addBodyPart(plaintextPart);
            content.addBodyPart(htmlPart);

            Message message = createBasicMessage(sender, recipients, replyTo, subject);
            message.setContent(content);
            return message;
        } catch (CedarRuntimeException e) {
View Full Code Here

TOP

Related Classes of javax.mail.internet.MimeMultipart

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.