Examples of MimeBodyPart


Examples of javax.mail.internet.MimeBodyPart

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

Examples of javax.mail.internet.MimeBodyPart

    private void add_file( SOSMailAttachment att throws Exception
    {
        if( !att.getFile().exists() )  throw new Exception( "Datei "+ att.getFile().getAbsolutePath() + " fehlt" );
       
       
        MimeBodyPart attachment = new MimeBodyPart();

        DataSource  data_source  = new File_data_source( att.getFile(), att.getContentType() );
        DataHandler data_handler = new DataHandler( data_source );

        attachment.setDataHandler( data_handler );
        attachment.setFileName   ( att.getFile().getName() );

        //Charset des Attachments setzen, wenn content_type text/ ist
        if (att.getContentType().startsWith("text/")){
          // Charset macht nur Sinn bei text/

            String s = "";
            FileReader fr = new FileReader( att.getFile() );
          
            for ( int c; ( c = fr.read() ) != -1; )
              s += ( (char) c );
            attachment.setText(s,att.getCharset());
           fr.close();
        }       
       
        Object m = message.getContent();
        if( !( m instanceof MimeMultipart ) )  throw new RuntimeException( getClass().getName() + "mime_message.getContent() liefert nicht MimeMultiPart" );
        ((MimeMultipart)m).addBodyPart( attachment );
        attachment.setHeader("Content-Transfer-Encoding", att.getEncoding());        
    }
View Full Code Here

Examples of net.rim.blackberry.api.mail.MimeBodyPart

                        addTextFieldToTableAndScreen(new RichTextField(
                                plainText), BODY);
                    }
                }
            } else if (bodyPart instanceof MimeBodyPart) {
                final MimeBodyPart mimeBodyPart = (MimeBodyPart) bodyPart;

                // If the content is text then display it
                final String contentType = mimeBodyPart.getContentType();
                if (contentType
                        .startsWith(BodyPart.ContentType.TYPE_TEXT_HTML_STRING)) {
                    final Object obj = mimeBodyPart.getContent();
                    if (obj != null) {
                        final String htmlText = new String((byte[]) obj);
                        addTextFieldToTableAndScreen(
                                new RichTextField(htmlText), BODY);
                    }
                } else if (contentType
                        .equals(BodyPart.ContentType.TYPE_MULTIPART_ALTERNATIVE_STRING)) {
                    // If the body part is a multi-part and it has the the
                    // content type of TYPE_MULTIPART_ALTERNATIVE_STRING, then
                    // recursively display the multi-part.
                    final Object obj = mimeBodyPart.getContent();
                    if (obj instanceof Multipart) {
                        final Multipart childMultipart = (Multipart) obj;
                        final String childMultipartType =
                                childMultipart.getContentType();
                        if (childMultipartType
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.