Package javax.mail

Examples of javax.mail.Multipart


        if (sendEmlMessage) {
            message = new MimeMessage(session, new BufferedInputStream(new FileInputStream(emlMessage)));
        } else {
            message = new MimeMessage(session);
            // handle body and attachments
            Multipart multipart = new MimeMultipart();
            final int attachmentCount = attachments.size();
            if (plainBody &&
               (attachmentCount == 0 ||  (mailBody.length() == 0 && attachmentCount == 1))) {
                if (attachmentCount == 1) { // i.e. mailBody is empty
                    File first = attachments.get(0);
                    InputStream is = null;
                    try {
                        is = new BufferedInputStream(new FileInputStream(first));
                        message.setText(IOUtils.toString(is));
                    } finally {
                        IOUtils.closeQuietly(is);
                    }
                } else {
                    message.setText(mailBody);
                }
            } else {
                BodyPart body = new MimeBodyPart();
                body.setText(mailBody);
                multipart.addBodyPart(body);
                for (File f : attachments) {
                    BodyPart attach = new MimeBodyPart();
                    attach.setFileName(f.getName());
                    attach.setDataHandler(new DataHandler(new FileDataSource(f.getAbsolutePath())));
                    multipart.addBodyPart(attach);
                }
                message.setContent(multipart);
            }
        }
View Full Code Here


    private String getSamplerData(Message message) throws MessagingException, IOException {
        StringBuilder sb = new StringBuilder();
        Object content = message.getContent(); // throws ME
        if (content instanceof Multipart) {
            Multipart multipart = (Multipart) content;
            String contentType = multipart.getContentType();
            ContentType ct = new ContentType(contentType);
            String boundary=ct.getParameter("boundary");
            for (int i = 0; i < multipart.getCount(); i++) { // throws ME
                sb.append("--");
                sb.append(boundary);
                sb.append("\n");
                BodyPart bodyPart = multipart.getBodyPart(i); // throws ME
                writeBodyPart(sb, bodyPart); // throws IOE, ME
            }
            sb.append("--");
            sb.append(boundary);
            sb.append("--");
View Full Code Here

                    msg.setRecipients(Message.RecipientType.TO, addressTo);

                    msg.setSubject(_subject);

                    //msg.setContent(_message, _mailFormat.toString());
                    final Multipart mp = this.getMailMultiPart();

                    msg.setContent(mp);

                    // Send the message
                    Transport.send(msg);
View Full Code Here

        //msg.setContent(_message, _mailFormat.toString());

        // attachments
        final MimeBodyPart[] attachments = this.getAttachments();

        final Multipart result = new MimeMultipart();
        // add body
        result.addBodyPart(body);
        // add attachments
        for (MimeBodyPart part : attachments) {
            result.addBodyPart(part);
        }

        return result;
    }
View Full Code Here

            messageBodyPart.setContent(mailBody, this.bodyMimeType);
        } else {
            messageBodyPart.setContent(this.body, this.bodyMimeType);
        }

        Multipart multipart = new MimeMultipart();
        multipart.addBodyPart(messageBodyPart);

        // process attachments
        Iterator iterAtt = this.attachments.iterator();

        while (iterAtt.hasNext()) {
            AttachmentDescriptor aD = (AttachmentDescriptor) iterAtt.next();
            messageBodyPart = new MimeBodyPart();

            if (!aD.isTextContent()) {
                Source inputSource = null;
                DataSource dataSource = null;

                if (aD.isURLSource()) {
                    inputSource = resolver.resolveURI(aD.strAttrSrc);

                    String iSS = inputSource.getURI();
                    if (iSS.startsWith("cocoon:")) {
                        iSS = iSS.substring(7, iSS.length());

                        if (this.contextPath != null) {
                            iSS = "http://localhost:" + this.port +
                                  this.contextPath + iSS;
                        } else {
                            iSS = "http://localhost:" + this.port + iSS;
                        }

                        if (getLogger().isDebugEnabled()) {
                            getLogger().debug("cocoon-URI changed to " + iSS);
                        }

                        dataSource = new URLDataSource(new URL(iSS));
                    } else {
                        dataSource = new URLDataSource(new URL(inputSource.getURI()));
                    }

                    messageBodyPart.setDataHandler(new DataHandler(dataSource));
                } else if (aD.isFileSource()) {
                    inputSource = resolver.resolveURI(aD.strAttrFile);
                    dataSource  = new URLDataSource(new URL(inputSource.getURI()));
                    messageBodyPart.setDataHandler(new DataHandler(dataSource));
                }
            } else {
                messageBodyPart.setContent(aD.strContent,
                                           aD.strAttrMimeType);
            }

            messageBodyPart.setFileName(aD.strAttrName);
            multipart.addBodyPart(messageBodyPart);
        }

        sm.setContent(multipart);

        //sm.setReturnOption(SMTPMessage.RETURN_FULL);
View Full Code Here

                addAttribute("file-name", part.getFileName());
            }
        } else {
            boolean hasAttachments = false;
            if (part.isMimeType("multipart/*")) {
                Multipart mp = (Multipart) part.getContent();
                if (mp.getCount() > 1) {
                    hasAttachments = true;
                    addAttribute("num-parts", String.valueOf(mp.getCount()));
                }
            }
            addAttribute("has-attachments", String.valueOf(hasAttachments));
        }

View Full Code Here

            }
            if (bestPart != null) {
                partToSAX(contentHandler, bestPart, 0);
            }
        } else if (part.isMimeType("multipart/*")) {
            Multipart mp = (Multipart) part.getContent();

            int count = mp.getCount();
            for (int i = 0; i < count; i++) {
                partToSAX(contentHandler, mp.getBodyPart(i), i);
            }
        } else if (part.isMimeType("message/rfc822")) {
            partToSAX(contentHandler, (Part) part.getContent(), 0);
        } else {
            /*
 
View Full Code Here

        plainPart.setText(body);

        MimeBodyPart htmlPart = new MimeBodyPart();
        htmlPart.setText("<html><body>" + body + "</body></html>");

        Multipart alt = new MimeMultipart("alternative");
        alt.addBodyPart(plainPart);
        alt.addBodyPart(htmlPart);

        Multipart mixed = new MimeMultipart("mixed");
        MimeBodyPart wrap = new MimeBodyPart();
        wrap.setContent(alt);
        mixed.addBodyPart(wrap);

        mixed.addBodyPart(plainPart);
        mixed.addBodyPart(htmlPart);

        message.setContent(mixed);
    }
View Full Code Here

      IOException, DecoderException {
    StringBuffer content = new StringBuffer("");
    if (p.isMimeType("text/plain")) {
      content.append((String) p.getContent());
    } else if (p.isMimeType("multipart/*")) {
      Multipart mp = (Multipart) p.getContent();
      int count = mp.getCount();
      for (int i = 0; i < count; i++)
        content.append(getContentFromPlainText(mp.getBodyPart(i)));
    } else {
      Object obj = p.getContent();
      if (obj instanceof Part)
        content.append(getContentFromPlainText((Part) p.getContent()));
    }
View Full Code Here

  private String getContentFromHTML(Part p) throws MessagingException,
      IOException, DecoderException, SAXException, TikaException {
    StringBuffer content = new StringBuffer("");
    if (p.isMimeType("multipart/*")) {
      Multipart mp = (Multipart) p.getContent();
      int count = mp.getCount();
      for (int i = 0; i < count; i++)
        content.append(getContentFromHTML(mp.getBodyPart(i)));
    } else if (p.isMimeType("text/html")) {
      HtmlParser parser = new HtmlParser();
      Metadata met = new Metadata();
      TextContentHandler handler = new TextContentHandler(
          new BodyContentHandler());
View Full Code Here

TOP

Related Classes of javax.mail.Multipart

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.