Examples of MimeMultipart


Examples of javax.mail.internet.MimeMultipart

      // message data
      msg.setSubject(subject, "utf-8");

      if (attachments != null && attachments.length > 0) {
        // with attachment use multipart message
        Multipart multipart = new MimeMultipart();
        // 1) add body part
        BodyPart messageBodyPart = new MimeBodyPart();
        messageBodyPart.setText(body);
        multipart.addBodyPart(messageBodyPart);
        // 2) add attachments
        for (File attachmentFile : attachments) {
          // abort if attachment does not exist
          if (attachmentFile == null || !attachmentFile.exists()) {
            result.setReturnCode(MailerResult.ATTACHMENT_INVALID);
            Tracing.logError("Tried to send mail wit attachment that does not exist::"
                + (attachmentFile == null ? null : attachmentFile.getAbsolutePath()), MailHelper.class);
            return msg;
          }
          messageBodyPart = new MimeBodyPart();
          DataSource source = new FileDataSource(attachmentFile);
          messageBodyPart.setDataHandler(new DataHandler(source));
          messageBodyPart.setFileName(attachmentFile.getName());
          multipart.addBodyPart(messageBodyPart);
        }
        // Put parts in message
        msg.setContent(multipart);
      } else {
        // without attachment everything is easy, just set as text
View Full Code Here

Examples of javax.mail.internet.MimeMultipart

               
                // Check the body
               
                Assert.assertNotNull(renderedMessage.getContent());
                Assert.assertTrue(renderedMessage.getContent() instanceof MimeMultipart);
                MimeMultipart body = (MimeMultipart) renderedMessage.getContent();
                Assert.assertEquals(body.getCount(), 1);
                Assert.assertNotNull(body.getBodyPart(0));
                Assert.assertTrue(body.getBodyPart(0) instanceof MimeBodyPart);
                MimeBodyPart bodyPart = (MimeBodyPart) body.getBodyPart(0);
                Assert.assertNotNull(bodyPart.getContent());
                Assert.assertEquals(bodyPart.getDisposition(), "inline");
                Assert.assertTrue(bodyPart.isMimeType("text/html"));               
            }           
        }.run();
View Full Code Here

Examples of javax.mail.internet.MimeMultipart

                Assert.assertEquals(to.getPersonal(), "Gavin King");
                InternetAddress from = (InternetAddress) renderedMessage.getFrom()[0];
                Assert.assertEquals(from.getAddress(), "do-not-reply@jboss.com");
                Assert.assertEquals(from.getPersonal(), "Seam");
                Assert.assertEquals(renderedMessage.getSubject(), "Try out Seam!");
                MimeMultipart body = (MimeMultipart) renderedMessage.getContent();               
   
                Assert.assertEquals(body.getCount(), 4); //3 Attachments and 1 MimeMultipart               
               
                // The root multipart/related
                Assert.assertNotNull(body.getBodyPart(0));
                Assert.assertTrue(body.getBodyPart(0) instanceof MimeBodyPart);
                MimeBodyPart bodyPart = (MimeBodyPart) body.getBodyPart(0);
                Assert.assertNotNull(bodyPart.getContent());
                Assert.assertTrue(bodyPart.getContent() instanceof MimeMultipart);
                Assert.assertTrue(bodyPart.isMimeType("multipart/related"));
               
                MimeMultipart attachments = (MimeMultipart) bodyPart.getContent();
               
                Assert.assertEquals(attachments.getCount(), 3); //2 Attachments and 1 MimeMultipart
               
                // Attachment 0 (the actual message)
                Assert.assertNotNull(attachments.getBodyPart(0));               
                Assert.assertTrue(attachments.getBodyPart(0) instanceof MimeBodyPart);
                bodyPart = (MimeBodyPart) attachments.getBodyPart(0);
                Assert.assertNotNull(bodyPart.getContent());
                Assert.assertNotNull(bodyPart.getContent());
                Assert.assertTrue(bodyPart.isMimeType("text/html"));
                Assert.assertEquals(bodyPart.getDisposition(), "inline");
               
                // Inline Attachment 1 // Attachment Jboss Logo
                Assert.assertNotNull(attachments.getBodyPart(1));               
                Assert.assertTrue(attachments.getBodyPart(1) instanceof MimeBodyPart);
                bodyPart = (MimeBodyPart) attachments.getBodyPart(1);
                Assert.assertNotNull(bodyPart.getContent());
                Assert.assertTrue(bodyPart.getContent() instanceof InputStream);
                Assert.assertEquals(bodyPart.getFileName(), "jboss.jpg");
                Assert.assertTrue(bodyPart.isMimeType("image/jpeg"));
                Assert.assertEquals(bodyPart.getDisposition(), "inline");
                Assert.assertNotNull(bodyPart.getContentID());
               
                // Inline Attachment 1 // Attachment Gavin Pic
                Assert.assertNotNull(attachments.getBodyPart(2));               
                Assert.assertTrue(attachments.getBodyPart(2) instanceof MimeBodyPart);
                bodyPart = (MimeBodyPart) attachments.getBodyPart(2);
                Assert.assertNotNull(bodyPart.getContent());
                Assert.assertTrue(bodyPart.getContent() instanceof InputStream);
                Assert.assertEquals(bodyPart.getFileName(), "Gavin_King.jpg");
                Assert.assertTrue(bodyPart.isMimeType("image/png"));
                Assert.assertEquals(bodyPart.getDisposition(), "inline");
View Full Code Here

Examples of javax.mail.internet.MimeMultipart

                // m:header
                Assert.assertNotNull(renderedMessage.getHeader("X-Sent-From"));
                Assert.assertEquals(renderedMessage.getHeader("X-Sent-From").length, 1);
                Assert.assertEquals(renderedMessage.getHeader("X-Sent-From")[0], "Seam");
               
                MimeMultipart body = (MimeMultipart) renderedMessage.getContent();
               
                // Check the alternative facet
                Assert.assertTrue(renderedMessage.getContentType().startsWith("multipart/mixed"));
                Assert.assertEquals(body.getCount(), 1);
                MimeBodyPart bodyPart = (MimeBodyPart) body.getBodyPart(0);
                Assert.assertTrue(bodyPart.getContentType().startsWith("multipart/alternative"));
                Assert.assertTrue(bodyPart.getContent() instanceof MimeMultipart);
                MimeMultipart bodyParts = (MimeMultipart) bodyPart.getContent();
                Assert.assertEquals(bodyParts.getCount(), 2);
                Assert.assertTrue(bodyParts.getBodyPart(0) instanceof MimeBodyPart);
                Assert.assertTrue(bodyParts.getBodyPart(1) instanceof MimeBodyPart);
                MimeBodyPart alternative = (MimeBodyPart) bodyParts.getBodyPart(0);
                MimeBodyPart html = (MimeBodyPart) bodyParts.getBodyPart(1);
                Assert.assertTrue(alternative.isMimeType("text/plain"));
                Assert.assertEquals(alternative.getDisposition(), "inline");
                Assert.assertTrue(html.isMimeType("text/html"));
                Assert.assertEquals(html.getDisposition(), "inline");
View Full Code Here

Examples of javax.mail.internet.MimeMultipart

                Assert.assertEquals(renderedMessage.getSubject(), "Plain text email sent by Seam");
               
                // Check the body
               
                Assert.assertNotNull(renderedMessage.getContent());
                MimeMultipart body = (MimeMultipart) renderedMessage.getContent();
                Assert.assertEquals(body.getCount(), 1);
                MimeBodyPart bodyPart = (MimeBodyPart) body.getBodyPart(0);
                Assert.assertNotNull(bodyPart.getContent());
                Assert.assertEquals(bodyPart.getDisposition(), "inline");
                Assert.assertTrue(bodyPart.isMimeType("text/plain"));
            }
        }.run();
View Full Code Here

Examples of javax.mail.internet.MimeMultipart

                Assert.assertNull(renderedMessage.getHeader("Priority"));
                Assert.assertNull(renderedMessage.getHeader("Importance"));
               
                // Check the body
               
                MimeMultipart body = (MimeMultipart) renderedMessage.getContent();
               
                // Check the alternative facet
                Assert.assertTrue(renderedMessage.getContentType().startsWith("multipart/mixed"));
                Assert.assertEquals(body.getCount(), 1);
                MimeBodyPart bodyPart = (MimeBodyPart) body.getBodyPart(0);
                Assert.assertTrue(bodyPart.getContentType().startsWith("multipart/alternative"));
                Assert.assertTrue(bodyPart.getContent() instanceof MimeMultipart);
                MimeMultipart bodyParts = (MimeMultipart) bodyPart.getContent();
                Assert.assertEquals(bodyParts.getCount(), 2);
                Assert.assertTrue(bodyParts.getBodyPart(0) instanceof MimeBodyPart);
                Assert.assertTrue(bodyParts.getBodyPart(1) instanceof MimeBodyPart);
                MimeBodyPart alternative = (MimeBodyPart) bodyParts.getBodyPart(0);
                MimeBodyPart html = (MimeBodyPart) bodyParts.getBodyPart(1);
                Assert.assertTrue(alternative.isMimeType("text/plain"));
                Assert.assertEquals(alternative.getDisposition(), "inline");
                Assert.assertTrue(html.isMimeType("text/html"));
                Assert.assertEquals(html.getDisposition(), "inline");
            }
View Full Code Here

Examples of javax.mail.internet.MimeMultipart

      InputStream response = method.getResponseBodyAsStream();
      BufferedInputStream in = new BufferedInputStream(response);
      String contentType = method.getResponseHeader("content-type").getValue();
      System.out.println(contentType);
      ByteArrayDataSource ds = new ByteArrayDataSource(in, contentType);
      MimeMultipart mimeMultipart = new MimeMultipart(ds);
      Assert.assertEquals(mimeMultipart.getCount(), 3);
      method.releaseConnection();

   }
View Full Code Here

Examples of javax.mail.internet.MimeMultipart

      Assert.assertEquals(HttpServletResponse.SC_OK, status);
      InputStream response = method.getResponseBodyAsStream();
      BufferedInputStream in = new BufferedInputStream(response);
      String contentType = method.getResponseHeader("content-type").getValue();
      ByteArrayDataSource ds = new ByteArrayDataSource(in, contentType);
      MimeMultipart mimeMultipart = new MimeMultipart(ds);
      Assert.assertEquals(mimeMultipart.getCount(), 1);

      BodyPart part = mimeMultipart.getBodyPart(0);
      InputStream is = part.getInputStream();

      Assert.assertEquals(3, part.getSize());

View Full Code Here

Examples of javax.mail.internet.MimeMultipart

      InputStream response = method.getResponseBodyAsStream();
      BufferedInputStream in = new BufferedInputStream(response);
      String contentType = method.getResponseHeader("content-type")
              .getValue();
      ByteArrayDataSource ds = new ByteArrayDataSource(in, contentType);
      MimeMultipart mimeMultipart = new MimeMultipart(ds);
      Assert.assertEquals(mimeMultipart.getCount(), 2);
      method.releaseConnection();
   }
View Full Code Here

Examples of javax.mail.internet.MimeMultipart

      final String toAddress, final List<FileItem> files) {

    Properties props = new Properties();
        Session session = Session.getDefaultInstance(props, null);
        try {
          Multipart mp = new MimeMultipart();
          MimeBodyPart htmlPart = new MimeBodyPart();
            htmlPart.setContent(htmlBody, "text/html");
            htmlPart.setHeader("Content-type", "text/html; charset=UTF-8");
            mp.addBodyPart(htmlPart);
            for (FileItem item : files) {
              MimeBodyPart attachment = new MimeBodyPart();
                attachment.setFileName(item.getFilename());
                String mimeType = MimeType.getContentTypeByExt(
                    FolderUtil.getFileExt(item.getFilename()));
                DataSource ds = new ByteArrayDataSource(item.getData(), mimeType);
                attachment.setDataHandler(new DataHandler(ds));
                mp.addBodyPart(attachment);
            }
            MimeMessage msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress(fromAddress, fromText));
            msg.addRecipient(Message.RecipientType.TO,
                             new InternetAddress(toAddress, toAddress));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.