Package javax.mail.internet

Examples of javax.mail.internet.MimeBodyPart


      mailMessage.setSentDate(new Date());
      //Properties props = ssn.getProperties();
          //props.put("mail.smtp.from", "<>");
 
          Multipart multipart = new MimeMultipart("related");
      MimeBodyPart messageBodyPart = new MimeBodyPart();
          messageBodyPart.setText("Welcome to JavaMail.");
          multipart.addBodyPart(messageBodyPart);
          mailMessage.setContent(multipart);
          mailMessage.setFrom(new InternetAddress("javayou@gmail.com","Winter Lau"));
         
          String mail_postfix = mailaddr.substring(mailaddr.indexOf('@')+1);
View Full Code Here


            if (multipart == null) {
                multipart = new MimeMultipart(multipartType);
            }

            MimeBodyPart part = new MimeBodyPart();

            // if param is wrapped JavaObject unwrap.
            if (obj instanceof Wrapper) {
                obj = ((Wrapper) obj).unwrap();
            }

            if (obj instanceof String) {
                part.setContent(obj.toString(), "text/plain");
            } else if (obj instanceof File) {
                FileDataSource source = new FileDataSource((File) obj);

                part.setDataHandler(new DataHandler(source));
            } else if (obj instanceof MimePart) {
                MimePartDataSource source = new MimePartDataSource((MimePart) obj);

                part.setDataHandler(new DataHandler(source));
            }

            // check if an explicit file name was given for this part
            if (filename != null && filename != Undefined.instance) {
                try {
                    part.setFileName(filename.toString());
                } catch (Exception x) {}
            } else if (obj instanceof File) {
                try {
                    part.setFileName(((File) obj).getName());
                } catch (Exception x) {}
            }

            multipart.addBodyPart(part);
        } catch (Exception mx) {
View Full Code Here

        try {
            if (buffer != null) {
                // if we also have a multipart body, add
                // plain string as first part to it.
                if (multipart != null) {
                    MimeBodyPart part = new MimeBodyPart();

                    part.setContent(buffer.toString(), "text/plain");
                    multipart.addBodyPart(part, 0);
                    message.setContent(multipart);
                } else {
                    message.setText(buffer.toString());
                }
View Full Code Here

        //Create attachments
        DataSource[] attachments = mailMessage.getAttachments();
        for (int i = 0; i < attachments.length; i++) {
            DataSource attachment = attachments[i];
            MimeBodyPart attachmentPart = createAttachmentPart(attachment);
            content.addBodyPart(attachmentPart);
        }
       
        //Create message body
        MimeBodyPart bodyPart = createMessageBodyPart(mailMessage.getBody(), mailMessage.isBodyHtml());
        content.addBodyPart(bodyPart);

        if (from == null) {
            message.setFrom();
        } else {
View Full Code Here

        }
        return (InternetAddress[]) result.toArray(new InternetAddress[result.size()]);
    }
   
    private static MimeBodyPart createAttachmentPart(DataSource attachment) throws MessagingException {
        MimeBodyPart attachmentPart = new MimeBodyPart();
        attachmentPart.setDataHandler(new DataHandler(attachment));
        attachmentPart.setDisposition(MimeBodyPart.ATTACHMENT);
        attachmentPart.setFileName(attachment.getName());
        return attachmentPart;
    }
View Full Code Here

        attachmentPart.setFileName(attachment.getName());
        return attachmentPart;
    }

    private static MimeBodyPart createMessageBodyPart(String body, boolean html) throws MessagingException {
        MimeBodyPart bodyPart = new MimeBodyPart();
        bodyPart.setText(body);
        bodyPart.setHeader("content-type", (html ? "text/html" : "text/plain"));
        return bodyPart;
    }
View Full Code Here

        // Create a Multipart
        Multipart multipart = new MimeMultipart( "alternative" );

        // Add text message
        BodyPart messageBodyPart = new MimeBodyPart();
        String text = "Summary\n-------\n\n" + summary + "\n\nDescription\n-----------\n\n" + description;
        messageBodyPart.setText( text );
        messageBodyPart.setDataHandler( new DataHandler( new ByteArrayDataSource( text,
                                                                                  "text/plain; charset=UTF8;" ) ) );
        multipart.addBodyPart( messageBodyPart );

        // Add ical
        messageBodyPart = new MimeBodyPart();
        String filename = "ical-" + type + "-" + taskId + ".ics";
        messageBodyPart.setFileName( filename );
        messageBodyPart.setHeader( "Content-Class",
                                   "urn:content-classes:calendarmessage" );
        messageBodyPart.setHeader( "Content-ID",
                                   "calendar_message" );
        String icalStr = getIcal( summary,
                                  description,
                                  startDate,
                                  priority,
                                  userInfo.getDisplayName( creator ),
                                  creatorEmail,
                                  type );

        messageBodyPart.setDataHandler( new DataHandler( new ByteArrayDataSource( icalStr,
                                                                                  "text/calendar; charset=UTF8; " ) ) );
        multipart.addBodyPart( messageBodyPart );

        message.setContent( multipart );
        message.saveChanges();
View Full Code Here

        }
        msg.setSentDate(new java.util.Date());
        // create and fill the first message part

        MimeBodyPart plainTextVersion = new MimeBodyPart();
        plainTextVersion.setDataHandler(new DataHandler(textDataSource));

        MimeBodyPart htmlPart = new MimeBodyPart();
        htmlPart.setDataHandler(new DataHandler(htmlDataSource));
        // create the Multipart
        // and its parts to it
        Multipart bodyAlternatives = new MimeMultipart("alternative");
        bodyAlternatives.addBodyPart(plainTextVersion);
        htmlPart.setHeader("Content-Type", "text/html; charset=UTF-8");
        bodyAlternatives.addBodyPart(htmlPart);



        // mbp1.setHeader("Content-Language", "fr");
        // add the Multipart to the message
        Multipart mainMultipart = new MimeMultipart();
        BodyPart body = new MimeBodyPart();
        body.setContent(bodyAlternatives);
        mainMultipart.addBodyPart(body);

        // mainMultipart.addBodyPart(getSerialializerRDFPart(mailModel));

        msg.setContent(mainMultipart);
View Full Code Here

        boolean htmlPartFound = false;
        boolean textPartFound = false;

        // loop through each Part of this message, looking for the ideal Part to save.
        for (int i = 0; i < multipart.getCount(); i++) {
          MimeBodyPart part = (MimeBodyPart)multipart.getBodyPart(i);
          String partContentType = part.getContentType();
          String disposition = part.getDisposition();

          if (disposition == null || disposition.toLowerCase().equals("inline")) {
            // do not scan the part if the disposition is "attachment"
            if ((partContentType.toLowerCase().indexOf("text/plain") > -1)) {
              // this Part is text/plain.
View Full Code Here

      //Most email clients add this line with the name of
      //their software and the version
      message.addHeader("X-Mailer", "Centraview v. " + CentraViewConfiguration.getVersion());

      message.setSubject(subject);
      BodyPart messageBodyPart = new MimeBodyPart();
      messageBodyPart.setContent(body, messageType);

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

      // Handle attachments
      if (attachments != null) {
        message.setContent(multipart);
        Iterator attachmentIterator = attachments.iterator();
        while (attachmentIterator.hasNext()) {
          messageBodyPart = new MimeBodyPart();
          CvFileVO thisAttachment = (CvFileVO) attachmentIterator.next();
          String path = thisAttachment.getPhysicalFolderVO().getFullPath(null, true) + thisAttachment.getName();
          DataSource source = new FileDataSource(path);
          messageBodyPart.setDataHandler(new DataHandler(source));
          messageBodyPart.setFileName(thisAttachment.getTitle());
          multipart.addBodyPart(messageBodyPart);
        }
      }

      message.setSentDate(new Date());
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.