Examples of MimeBodyPart


Examples of javax.mail.internet.MimeBodyPart

    props.setProperty("mail.smtp.host", "localhost");
    props.setProperty("mail.smtp.port", SMTP_PORT+"");
    Session session = Session.getInstance(props);

    MimeMessage baseMsg = new MimeMessage(session);
    MimeBodyPart bp1 = new MimeBodyPart();
    bp1.setHeader("Content-Type", "text/plain");
    bp1.setContent("Hello World!!!", "text/plain; charset=\"ISO-8859-1\"");

    // Attach the file
    MimeBodyPart bp2 = new MimeBodyPart();
    FileDataSource fileAttachment = new FileDataSource(BIGFILE_PATH);
    DataHandler dh = new DataHandler(fileAttachment);
    bp2.setDataHandler(dh);
    bp2.setFileName(fileAttachment.getName());

    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(bp1);
    multipart.addBodyPart(bp2);
View Full Code Here

Examples of javax.mail.internet.MimeBodyPart

        InputStream oLongVarBin = oRSet.getBinaryStream(17);

        if (!oRSet.wasNull()) {
          if (DebugFile.trace) DebugFile.writeln("MimeMultipart.addBodyPart(new MimeBodyPart(InputStream)");
          oParts.addBodyPart(new MimeBodyPart(oLongVarBin));
        }

        oRSet.close();
        oRSet = null;
View Full Code Here

Examples of javax.mail.internet.MimeBodyPart

    MimeMessage oMsg;
    InternetAddress oFrom, oTo;
    MimeMultipart oAltParts = new MimeMultipart("alternative");
   
    // Set alternative plain/text part to avoid spam filters as much as possible
    MimeBodyPart oMsgTextPart = new MimeBodyPart();
  oMsgTextPart.setText("This message is HTML, but your e-mail client is not capable of rendering HTML messages", "UTF-8", "plain");

    MimeBodyPart oMsgBodyPart = new MimeBodyPart();
 
    try {
      if (null==getParameter("tx_sender"))
        oFrom = new InternetAddress(getParameter("tx_from"));
      else
        oFrom = new InternetAddress(getParameter("tx_from"), getParameter("tx_sender"));

      if (DebugFile.trace) DebugFile.writeln("to: " + oAtm.getStringNull(DB.tx_email, "ERROR Atom[" + String.valueOf(oAtm.getInt(DB.pg_atom)) + "].tx_email is null!"));

      oTo = new InternetAddress(oAtm.getString(DB.tx_email), oAtm.getStringNull(DB.tx_name,"") + " " + oAtm.getStringNull(DB.tx_surname,""));
    }
    catch (AddressException adre) {
      if (DebugFile.trace) DebugFile.writeln("AddressException " + adre.getMessage() + " job " + getString(DB.gu_job) + " atom " + String.valueOf(oAtm.getInt(DB.pg_atom)));

      oFrom = null;
      oTo = null;

      throw new MessagingException ("AddressException " + adre.getMessage() + " job " + getString(DB.gu_job) + " atom " + String.valueOf(oAtm.getInt(DB.pg_atom)));
    }

    if (DebugFile.trace) DebugFile.writeln("new MimeMessage([Session])");

    oMsg = new MimeMessage(oMailSession);

    oMsg.setSubject(getParameter("tx_subject"));

    oMsg.setFrom(oFrom);

    if (DebugFile.trace) DebugFile.writeln("MimeMessage.addRecipient(MimeMessage.RecipientType.TO, " + oTo.getAddress());

    oMsg.addRecipient(MimeMessage.RecipientType.TO, oTo);

    String sSrc = null, sCid = null;

    try {
   
    // Insert Web Beacon just before </BODY> tag
    if (Yes.equals(getParameter("bo_webbeacon"))) {
      int iEndBody = Gadgets.indexOfIgnoreCase(oReplaced, "</body>", 0);
      if (iEndBody>0) {
        String sWebBeaconDir = getProperty("webbeacon");       
        if (sWebBeaconDir==null) {
          sWebBeaconDir = Gadgets.chomp(getParameter("webserver"),'/')+"hipermail/";
        } else if (sWebBeaconDir.trim().length()==0) {
          sWebBeaconDir = Gadgets.chomp(getParameter("webserver"),'/')+"hipermail/";
        }
        oReplaced = oReplaced.substring(0, iEndBody)+"<img src=\""+Gadgets.chomp(sWebBeaconDir,'/')+"web_beacon.jsp?gu_job="+getString(DB.gu_job)+"&pg_atom="+String.valueOf(oAtm.getInt(DB.pg_atom))+"&gu_company="+oAtm.getStringNull(DB.gu_company,"")+"&gu_contact="+oAtm.getStringNull(DB.gu_contact,"")+"&tx_email="+oAtm.getStringNull(DB.tx_email,"")+"\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" />"+oReplaced.substring(iEndBody);         
      } // fi </body>
    } // fi (bo_webbeacon)
     
      // Images may be attached into message or be absolute http source references
      if (Yes.equals(getParameter("bo_attachimages"))) {

        if (DebugFile.trace) DebugFile.writeln("BodyPart.setText("+oReplaced.replace('\n',' ')+",UTF-8,html)");

        oMsgBodyPart.setText(oReplaced, "UTF-8", "html");

        // Create a related multi-part to combine the parts
        MimeMultipart oRelatedMultiPart = new MimeMultipart("related");
        oRelatedMultiPart.addBodyPart(oMsgBodyPart);

        Iterator<String> oImgs = oDocumentImages.keySet().iterator();

        while (oImgs.hasNext()) {
          MimeBodyPart oImgBodyPart = new MimeBodyPart();

          sCid = oImgs.next();
          sSrc = oDocumentImages.get(sCid);

          if (sSrc.startsWith("www."))
            sSrc = "http://" + sSrc;

          if (sSrc.startsWith("http://") || sSrc.startsWith("https://")) {
            oImgBodyPart.setDataHandler(new DataHandler(new URL(sSrc)));
          }
          else {
            oImgBodyPart.setDataHandler(new DataHandler(new FileDataSource(sSrc)));
          }

          oImgBodyPart.setContentID(sCid);
          oImgBodyPart.setDisposition(oImgBodyPart.INLINE);
          oImgBodyPart.setFileName(sCid);

          // Add part to multi-part
          oRelatedMultiPart.addBodyPart(oImgBodyPart);
        } // wend

        MimeBodyPart oTextHtmlRelated = new MimeBodyPart();
        oTextHtmlRelated.setContent(oRelatedMultiPart);

    oAltParts.addBodyPart(oMsgTextPart);
    oAltParts.addBodyPart(oTextHtmlRelated);

      MimeMultipart oSentMsgParts = new MimeMultipart("mixed");
     MimeBodyPart oMixedPart = new MimeBodyPart();
       
        oMixedPart.setContent(oAltParts);
        oSentMsgParts.addBodyPart(oMixedPart);
       
        oMsg.setContent(oSentMsgParts);
      }
View Full Code Here

Examples of javax.mail.internet.MimeBodyPart

      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 {
View Full Code Here

Examples of javax.mail.internet.MimeBodyPart

             attachment.setValue(doc);
             attachment.encodeEnd(FacesContext.getCurrentInstance());
            
             // verify we built the message
             Assert.assertEquals(message.getAttachments().size(), 1);
             MimeBodyPart bodyPart = message.getAttachments().get(0);
             Assert.assertEquals(bodyPart.getFileName(), "filename.pdf");
             Assert.assertEquals(bodyPart.getDisposition(),"attachment");
          }
       }.run();
    }
View Full Code Here

Examples of javax.mail.internet.MimeBodyPart

                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");

            }           
        }.run();
      
    }
View Full Code Here

Examples of javax.mail.internet.MimeBodyPart

                // 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.MimeBodyPart

                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");
            }
        }.run();
    }
View Full Code Here

Examples of javax.mail.internet.MimeBodyPart

                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.MimeBodyPart

                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");
                Assert.assertNotNull(bodyPart.getContentID());
               
                // Root Attachment 0
                Assert.assertNotNull(body.getBodyPart(1));               
                Assert.assertTrue(body.getBodyPart(1) instanceof MimeBodyPart);
                bodyPart = (MimeBodyPart) body.getBodyPart(1);
                Assert.assertNotNull(bodyPart.getContent());
                Assert.assertTrue( bodyPart.getContent() instanceof InputStream);
                Assert.assertEquals(bodyPart.getFileName(), "numbers.csv");
                Assert.assertTrue(bodyPart.isMimeType("content/unknown"));
                Assert.assertEquals(bodyPart.getDisposition(), "attachment");
                Assert.assertNull(bodyPart.getContentID());               
               
                // Root Attachment 1
                Assert.assertNotNull(body.getBodyPart(2));               
                Assert.assertTrue(body.getBodyPart(2) instanceof MimeBodyPart);
                bodyPart = (MimeBodyPart) body.getBodyPart(2);
                Assert.assertNotNull(bodyPart.getContent());
                Assert.assertTrue(bodyPart.getContent() instanceof String);
                Assert.assertEquals(bodyPart.getFileName(), "whyseam.pdf");
                Assert.assertEquals(bodyPart.getDisposition(), "attachment");
                Assert.assertNull(bodyPart.getContentID());
               
                // Root Attachment 3
                Assert.assertNotNull(body.getBodyPart(3));               
                Assert.assertTrue(body.getBodyPart(3) instanceof MimeBodyPart);
                bodyPart = (MimeBodyPart) body.getBodyPart(3);
                Assert.assertNotNull(bodyPart.getContent());
                Assert.assertEquals(bodyPart.getFileName(), "excel.xls");
                Assert.assertTrue(bodyPart.isMimeType("application/vnd.ms-excel"));
                Assert.assertEquals(bodyPart.getDisposition(), "attachment");
                Assert.assertNull(bodyPart.getContentID());               
               
            }           
        }.run();
      
    }
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.