Package javax.mail

Examples of javax.mail.Multipart


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


      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

  
      if (mimeMessage.isMimeType("text/plain")) {
        return (String) content;
       
      } else if (mimeMessage.isMimeType("multipart/*")) {
          Multipart mp = (Multipart) mimeMessage.getContent();
          int numParts = mp.getCount();
  
          for (int i = 0; i < numParts; ++i) {
  
            if (mp.getBodyPart(i).isMimeType("text/plain")) {
              return (String) mp.getBodyPart(i).getContent();
  
            } else if (mp.getBodyPart(i).isMimeType("multipart/*")) {
                MimeMultipart mmp = (MimeMultipart) mp.getBodyPart(i).getContent();
                int numBodyParts = mmp.getCount();
  
                for (int j = 0; j < numBodyParts; ++j) {
                  if (mmp.getBodyPart(j).isMimeType("text/plain")) {
                    return (String) mmp.getBodyPart(j).getContent();
View Full Code Here

        String fileName = null;
       
        if (part.isMimeType("text/plain")) {
          // body
        } else if (part.isMimeType("multipart/*")) {
          Multipart multipart = (Multipart)part.getContent();
          int count = multipart.getCount();
          for (int i = 0; i < count; i++) {
              processAttachment(multipart.getBodyPart(i));
          }
        } else if (part.isMimeType("message/rfc822")) { // attachment is a message
            hasAttachment = true;
            extension = ".eml";
        } else if (part.isMimeType("text/html")) {      // HTML?
View Full Code Here

        }
      
        BodyPart messageBodyPart = new MimeBodyPart();
        messageBodyPart.setText(forwardSubject);

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

        messageBodyPart = new MimeBodyPart();
        messageBodyPart.setDataHandler(message.getDataHandler());

        multipart.addBodyPart(messageBodyPart);

        forward.setContent(multipart);

        Transport.send(forward);
       
View Full Code Here

   
    // -- Create a new message --
    BodyPart msg = new MimeBodyPart();
    msg.setDataHandler(new DataHandler(new ByteArrayDataSource(htmlBody, "text/html; charset=\"utf-8\"")));
   
    Multipart multipart = new MimeMultipart();
   
    BodyPart iCalAttachment = new MimeBodyPart();
    iCalAttachment.setDataHandler(new DataHandler(new javax.mail.util.ByteArrayDataSource(new ByteArrayInputStream(iCalMimeBody), "text/calendar;method=REQUEST;charset=\"UTF-8\"")));

    multipart.addBodyPart(iCalAttachment);
    multipart.addBodyPart(msg);
   
    mimeMessage.setContent(multipart);
   
    // -- Set some other header information --
    //mimeMessage.setHeader("X-Mailer", "XML-Mail");
View Full Code Here

//            System.err.println("CONTENT PLAIN:"+bodytext);
        } else if (part.isMimeType("text/html") && !conname) {
            bodytext.append((String) part.getContent());
//            System.err.println("CONTENT html:"+bodytext);
        } else if (part.isMimeType("multipart/*")) {
            Multipart multipart = (Multipart) part.getContent();
            int counts = multipart.getCount();
            for (int i = 0; i < counts; i++) {
                bodytext.append(getMailContent(multipart.getBodyPart(i)));
            }
//            System.err.println("CONTENT multi:"+bodytext);
        } else if (part.isMimeType("message/rfc822")) {//TODO codec ?
            bodytext.append(getMailContent((Part) part.getContent()));
//            System.err.println("CONTENT rcf:"+bodytext);
View Full Code Here

     */
    private boolean isContainAttach(Part part) throws Exception {
        boolean attachflag = false;
//        String contentType = part.getContentType();
        if (part.isMimeType("multipart/*")) {
            Multipart mp = (Multipart) part.getContent();
            for (int i = 0; i < mp.getCount(); i++) {
                BodyPart mpart = mp.getBodyPart(i);
                String disposition = mpart.getDisposition();
                if ((disposition != null)
                        && ((disposition.equals(Part.ATTACHMENT)) || (disposition.equals(Part.INLINE)))) {
                    attachflag = true;
                } else if (mpart.isMimeType("multipart/*")) {
View Full Code Here

        }
    }

    private boolean matchPart(Part part) throws MessagingException, IOException {
        if (part.isMimeType("multipart/*")) {
            Multipart mp = (Multipart) part.getContent();
            int count = mp.getCount();
            for (int i=0; i < count; i++) {
                BodyPart bp = mp.getBodyPart(i);
                if (matchPart(bp)) {
                    return true;
                }
            }
            return false;
View Full Code Here

            msg.addHeader("X-Jenkins-Result", context.getBuild().getResult().toString());
        }
        msg.setSentDate(new Date());
        setSubject(context, msg, charset);

        Multipart multipart = new MimeMultipart();
        multipart.addBodyPart(getContent(context, charset));

        AttachmentUtils attachments = new AttachmentUtils(attachmentsPattern);
        attachments.attach(multipart, context);

        // add attachments from the email type if they are setup
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.