Package javax.mail.internet

Examples of javax.mail.internet.MimeBodyPart


    }

    protected MimeMultipart getMimeMultipart(final byte[] encodedBytes, final InternetHeaders headers)
        throws MessagingException {
        final MimeMultipart mp = new MimeMultipart();
        final MimeBodyPart part = new MimeBodyPart(headers, encodedBytes);
        mp.addBodyPart(part);
        return mp;
    }
View Full Code Here


    String toStr;
    String ccStr;
    String fromStr;
    String subjectStr;
    String msgBody;
    MimeBodyPart tmpBodyPart;
    Properties props = hr.request.props;

    /* Get our necessary arguments - set connHandle.sendmailerror if we are
     * missing any that are mandatory
     */

    toStr = hr.get("to");

    if (toStr == null) {
     props.put(connHandle + "sendmailerror","Missing 'to' field");
     hr.request.log(Server.LOG_ERROR,connHandle,"Missing 'to' field in <sendmail>");
     return false;
    }

    fromStr = hr.get("from");

    if (fromStr == null) {
     props.put(connHandle + "sendmailerror","Missing 'from' field");
     hr.request.log(Server.LOG_ERROR,connHandle,"Missing 'from' field in <sendmail>");
     return false;
    }

    subjectStr = hr.get("subject");
    ccStr = hr.get("cc");

    /* Get our message body */

    msgBody = hr.get("body");
    hr.request.log(Server.LOG_DIAGNOSTIC,connHandle,"Message body = " + msgBody);

    /* Create our sendMsg object */

    sendMsg = new MimeMessage(defMailSession);

    /* Fill in the necessary message parts */

    sendMsg.setHeader("To",toStr);
    sendMsg.setHeader("From",fromStr);
 
    if (subjectStr != null) {
      sendMsg.setSubject(subjectStr);
    } else {
      sendMsg.setSubject("(no subject)");
    }

    if (ccStr != null) {
      sendMsg.setHeader("Cc",ccStr);
    }

    String bccStr = hr.get("bcc");
    if (bccStr != null && !bccStr.equals("")) {
      sendMsg.setHeader("Bcc",bccStr);
    }

    if (sendMultipart == null) {
      sendMultipart = new MimeMultipart();
    }

    tmpBodyPart = new MimeBodyPart();

    if (msgBody != null) {
      tmpBodyPart.setText(msgBody);
    } else {
      tmpBodyPart.setText("");
    }

    sendMultipart.addBodyPart(tmpBodyPart,0);

    /* Succeeded in building the message - return true */
 
View Full Code Here

   */

  public void tag_part(RewriteContext hr) {
    String connHandle = getConnHandle(hr);
    Properties props = hr.request.props;
    MimeBodyPart tmpBodyPart;
    String contentType;
    String partData;
    String partName;
    String partEncoding;
    byte[] partDataBytes;

    hr.killToken();
    debug(hr);

    /* Check to see if we need to create a new MimeMultipart */

    if (sendMultipart == null) {
      sendMultipart = new MimeMultipart();
    }

    /* Collect our parameter values */

    partData = hr.get("body");

    if (partData == null) {
      props.put(connHandle + "sendmailerror","Missing 'body' field in <part>");
      hr.request.log(Server.LOG_ERROR,connHandle,"Missing 'body' field in <part>");
      return;
    }

    partEncoding = hr.get("encoding");

    if (partEncoding == null) {
      props.put(connHandle + "sendmailerror","Missing 'encoding' field in <part>");
      hr.request.log(Server.LOG_ERROR,connHandle,"Missing 'encoding' field in <part>");
      return;
    }

    partName = hr.get("name");

    if (partName == null) {
      partName = "No Name";
    }

    contentType = hr.get("content-type");

    if (contentType == null) {
      contentType = "application/octet-stream";
    }
   
    /* Get the bytes from our String partData */

    partDataBytes = getBytes(partData);

    /* Now let's create a tmp MimeBodyPart and populate it */

    try {
      tmpBodyPart = new MimeBodyPart(new InternetHeaders(),partDataBytes);

      /* Now setup whatever headers we need */

      tmpBodyPart.setHeader("Content-Type",contentType);
      tmpBodyPart.setFileName(partName);
      tmpBodyPart.setDescription(partName);
    
      if (!partEncoding.equals("none")) {
        tmpBodyPart.setHeader("Content-Transfer-Encoding",partEncoding);
      }

      /* Attach this tmpBodyPart to our current sendMultipart */

      sendMultipart.addBodyPart(tmpBodyPart);
View Full Code Here

        // compulsory parts and one optional part...
        MimeMultipartReport multiPart = new MimeMultipartReport();
        multiPart.setReportType("disposition-notification");
       
        // Part 1: The 'human-readable' part
        MimeBodyPart humanPart = new MimeBodyPart();
        humanPart.setText(humanText);
        multiPart.addBodyPart(humanPart);

        // Part 2: MDN Report Part
        // 1) reporting-ua-field
        StringBuilder mdnReport = new StringBuilder(128);
        mdnReport.append("Reporting-UA: ");
        mdnReport.append((reporting_UA_name == null ? "" : reporting_UA_name));
        mdnReport.append("; ");
        mdnReport.append((reporting_UA_product == null ? "" : reporting_UA_product));
        mdnReport.append("\r\n");
        // 2) original-recipient-field
        if (null != original_recipient)
        {
            mdnReport.append("Original-Recipient: ");
            mdnReport.append("rfc822; ");
            mdnReport.append(original_recipient);
            mdnReport.append("\r\n");
        }
        // 3) final-recipient-field
        mdnReport.append("Final-Recepient: ");
        mdnReport.append("rfc822; ");
        mdnReport.append((final_recipient == null ? "" : final_recipient));
        mdnReport.append("\r\n");
        // 4) original-message-id-field
        mdnReport.append("Original-Message-ID: ");
        mdnReport.append((original_message_id == null ? "" : original_message_id));
        mdnReport.append("\r\n");
        // 5) disposition-field
        mdnReport.append(disposition.toString());
        mdnReport.append("\r\n");
        MimeBodyPart mdnPart = new MimeBodyPart();
        mdnPart.setContent(mdnReport.toString(), "message/disposition-notification");
        multiPart.addBodyPart(mdnPart);

        // Part 3: The optional third part, the original message is omitted.
        // We don't want to propogate over-sized, virus infected or
        // other undesirable mail!
View Full Code Here

        if (message instanceof MimeMessage) {
            MimeMessage mimeMessage = (MimeMessage) message;
            if (mimeMessage.getContent() instanceof Multipart) {
                Multipart mp = (Multipart) mimeMessage.getContent();
                for (int i=0; i<mp.getCount(); i++) {
                    MimeBodyPart mbp = (MimeBodyPart) mp.getBodyPart(i);
                    int size = mbp.getSize();
                    if (size != -1) {
                        metrics.incrementBytesReceived(size);
                    }
                }
            } else {
View Full Code Here

        ContentType contentType = new ContentType(message.getContentType());
        if (contentType.getBaseType().equalsIgnoreCase("multipart/mixed")) {
            Multipart multipart = (Multipart)message.getContent();
            Part textMainPart = null;
            for (int i=0; i<multipart.getCount(); i++) {
                MimeBodyPart bodyPart = (MimeBodyPart)multipart.getBodyPart(i);
                ContentType partContentType = new ContentType(bodyPart.getContentType());
                if (axisCfg.getMessageBuilder(partContentType.getBaseType()) != null) {
                    if (partContentType.getBaseType().equalsIgnoreCase("text/plain")) {
                        // If it's a text/plain part, remember it. We will return
                        // it later if we don't find something more interesting.
                        textMainPart = bodyPart;
View Full Code Here

    Session mailSession = Session.getInstance(props, null);
        String msgBody = "Click" + "<a href='http://stewiemaze.appspot.com/register-player.do/validate.do?nickname=" + nickname +"'>" +
            " Here</a> to validate you account";
        Message msg = new MimeMessage(mailSession);
        Multipart mp = new MimeMultipart();
        MimeBodyPart htmlPart = new MimeBodyPart();
        htmlPart.setContent(msgBody, "text/html");
        mp.addBodyPart(htmlPart);
        msg.setContent(mp);
        msg.setFrom(new InternetAddress("admin@stewiemaze.appspotmail.com"));
        msg.addRecipient(Message.RecipientType.TO,
                         new InternetAddress(email, nickname));
View Full Code Here

            try {
                byte[] bytes = createBytes(value, cls, mimeTypes);
                // Create MIME Body Part
                InternetHeaders ih = new InternetHeaders();
                ih.setHeader(HTTPConstants.HEADER_CONTENT_TYPE, mimeTypes[0]);
                MimeBodyPart mbp = new MimeBodyPart(ih, bytes);

                //Create a data source for the MIME Body Part
                MimePartDataSource ds = new MimePartDataSource(mbp);

                dh = new DataHandler(ds);
                mbp.setHeader(HTTPConstants.HEADER_CONTENT_ID, cid);
            } catch (Exception e) {
                throw ExceptionFactory.makeWebServiceException(e);
            }
        }
        return dh;
View Full Code Here

      MimeMultipart multipPartContent = new MimeMultipart("alternative");

      if (attachment != null && attachment.size() != 0)
      {
         MimeBodyPart contentPartRoot = new MimeBodyPart();
         if (mimeType != null && mimeType.indexOf("text/plain") > -1)
            contentPartRoot.setContent(body, "text/plain; charset=utf-8");
         else
            contentPartRoot.setContent(body, "text/html; charset=utf-8");
         MimeBodyPart mimeBodyPart1 = new MimeBodyPart();
         mimeBodyPart1.setContent(body, mimeType);
         multipPartContent.addBodyPart(mimeBodyPart1);
         multipPartRoot.addBodyPart(contentPartRoot);
         for (Attachment att : attachment)
         {
            InputStream is = att.getInputStream();
            MimeBodyPart mimeBodyPart = new MimeBodyPart();
            ByteArrayDataSource byteArrayDataSource = new ByteArrayDataSource(is, att.getMimeType());
            mimeBodyPart.setDataHandler(new DataHandler(byteArrayDataSource));

            mimeBodyPart.setDisposition(Part.ATTACHMENT);
            if (att.getName() != null)
               mimeBodyPart.setFileName(MimeUtility.encodeText(att.getName(), "utf-8", null));
            multipPartRoot.addBodyPart(mimeBodyPart);
         }
         mimeMessage.setContent(multipPartRoot);
      }
      else
View Full Code Here

      MimeMultipart multipPartContent = new MimeMultipart("alternative");

      if (attachment != null && attachment.size() != 0)
      {
         MimeBodyPart contentPartRoot = new MimeBodyPart();
         if (mimeType != null && mimeType.indexOf("text/plain") > -1)
            contentPartRoot.setContent(body, "text/plain; charset=utf-8");
         else
            contentPartRoot.setContent(body, "text/html; charset=utf-8");
         MimeBodyPart mimeBodyPart1 = new MimeBodyPart();
         mimeBodyPart1.setContent(body, mimeType);
         multipPartContent.addBodyPart(mimeBodyPart1);
         multipPartRoot.addBodyPart(contentPartRoot);
         for (Attachment att : attachment)
         {
            InputStream is = att.getInputStream();
            MimeBodyPart mimeBodyPart = new MimeBodyPart();
            ByteArrayDataSource byteArrayDataSource = new ByteArrayDataSource(is, att.getMimeType());
            mimeBodyPart.setDataHandler(new DataHandler(byteArrayDataSource));

            mimeBodyPart.setDisposition(Part.ATTACHMENT);
            if (att.getName() != null)
               mimeBodyPart.setFileName(MimeUtility.encodeText(att.getName(), "utf-8", null));
            multipPartRoot.addBodyPart(mimeBodyPart);
         }
         mimeMessage.setContent(multipPartRoot);
      }
      else
View Full Code Here

TOP

Related Classes of javax.mail.internet.MimeBodyPart

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.