Package javax.mail

Examples of javax.mail.Multipart


      mailMessage.setSubject("Hello MAIL");
      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);
          //System.out.println("mail postfix is " + mail_postfix);
View Full Code Here


                              new InternetAddress( userInfo.getEmailForEntity( owner ) ) );
        message.setSubject( "Task Assignment " + type + " Event: " + name );
        message.setSentDate( new Date() );

        // 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();

        Transport.send( message );
View Full Code Here

        sbuf.append(tail);
      }

      part.setContent(sbuf.toString(), getEmailContentType());

      Multipart mp = new MimeMultipart();
      mp.addBodyPart(part);
      msg.setContent(mp);
     
      msg.setSentDate(new Date());
     
      Transport.send(msg);
View Full Code Here

        // get body part
        Object content = mesage[i].getContent();

        if (content instanceof Multipart)
        {
          Multipart multipart = (Multipart)content;

          for (int j = 0, n = multipart.getCount(); j < n; j++)
          {
            Part part = (Part)multipart.getBodyPart(j);
            String contentType = part.getContentType();
            String disposition = part.getDisposition();

            if (disposition == null)
            {
View Full Code Here

      Object o = message.getContent();
      if (o instanceof String)
      {
        msgBody.append((String) o);
      }else if(o instanceof Multipart){
        Multipart mp = (Multipart)o;
        int countMultipart = mp.getCount();

        for (int j = 0; j < countMultipart; j++)
        {
          // Part are numbered starting at 0
          BodyPart b = mp.getBodyPart(j);
          String mimeType2 = b.getContentType();
          String disposition2 = b.getDisposition();

          Object o2 = b.getContent();

          if (o2 instanceof String)
          {
            if (mimeType2 != null &&
                (mimeType2.toLowerCase().indexOf("text/plain") != -1 || mimeType2.toLowerCase().indexOf("text/html") != -1) &&
                (disposition2 == null ||(disposition2!=null && !disposition2.equals(Part.ATTACHMENT))))
            {
              if (mimeType2.toLowerCase().indexOf("text/html")>=0)
              {
                // HTML message body
                msgBody.append(b.getContent().toString());
              }else{
                // plain text part
                msgBody.append(b.getContent().toString());
              }
              if (! msgBody.toString().equals(""))
              {
                break;
              }
            }
          }else if(o2 instanceof Multipart){
            //"**This BodyPart is a nested Multipart.  ");
            Multipart mp2 = (Multipart)o2;
            int countMultipart1 = mp2.getCount();

            for (int k = 0; k < countMultipart1; k++)
            {
              // Part are numbered starting at 0
              BodyPart b2 = mp2.getBodyPart(k);
              String mimeType3 = b2.getContentType();
              String disposition3 = b2.getDisposition();

              Object o3 = b2.getContent();

View Full Code Here

      message.setFrom(new InternetAddress(from));
      message.setSubject(subject);
      BodyPart messageBodyPart        = new MimeBodyPart();
      String messageContext = "text/plain";
      messageBodyPart.setContent(body, messageContext);
      Multipart multipart             = new MimeMultipart();
      multipart.addBodyPart(messageBodyPart);
      messageBodyPart = new MimeBodyPart();
      message.setContent(multipart);
      Transport.send(message);
    }catch(Exception e){
      System.out.println("[Exception]: SendMailEJB.sendMailMessage:");
View Full Code Here

      } //end of if statement ((body.indexOf("&lt;") > -1) && (body.indexOf("&gt;") > -1))
*/

      messageBodyPart.setContent(body, messageContext);

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

      messageBodyPart = new MimeBodyPart();
      HashMap attchmentids            = mailmessage.getAttachFileIDs();

      if ((attchmentids != null) && (attchmentids.size() != 0))
      {

        Set col       = attchmentids.keySet();
        Iterator itt  = col.iterator();
        int i         = 0;
        while (itt.hasNext())
        {
          String fileid        = (String) itt.next();
          String name          = (String) attchmentids.get(fileid);
          cvdl.setSql("email.savedraftattchment");
          cvdl.setInt(1, messageid);
          cvdl.setString(2, name);
          cvdl.setInt(3, Integer.parseInt(fileid));
          cvdl.executeUpdate();
          cvdl.clearParameters();
          i++;

          CvFileFacade cvfile  = new CvFileFacade();
          CvFileVO cvfilevo    = cvfile.getEmailAttachment(userId, Integer.parseInt(fileid), this.dataSource);

          String path          = cvfilevo.getPhysicalFolderVO().getFullPath(null, true) + cvfilevo.getName();

          DataSource source    = new FileDataSource(path);
          messageBodyPart.setDataHandler(new DataHandler(source));
          messageBodyPart.setFileName(name);
          multipart.addBodyPart(messageBodyPart);

        } //end of while loop(itt.hasNext())
      } //end of if statement ((attchmentids != null) && (attchmentids.size() != 0))
      // delete mail from  drafts
      if (mailmessage.getMessageID() != 0)
View Full Code Here

          message.setFrom(new InternetAddress(from));
          message.setSubject(subject);
          BodyPart messageBodyPart        = new MimeBodyPart();
          String messageContext = "text/plain";
          messageBodyPart.setContent(body, messageContext);
          Multipart multipart             = new MimeMultipart();
          multipart.addBodyPart(messageBodyPart);
          messageBodyPart = new MimeBodyPart();
          message.setContent(multipart);
          Transport.send(message);
        }//end of try block
        catch (Exception e)
View Full Code Here

        {
          mEmailMessage.setContent(o.toString());
        }
        else if (o instanceof Multipart)
        {
          Multipart mp = (Multipart) o;

          int count3 = mp.getCount();

          /*
           * This is for *.eml file j = 0 is for text, j = 1 is for
           * HTML.
           */
          for (int j = 0; j < count3; j++)
          {
            // Part are numbered starting at 0
            BodyPart b = mp.getBodyPart(j);

            Object o2 = b.getContent();
            if ((o2 instanceof String))
            {
              mEmailMessage.setContent(o2.toString());
            }
            else if (o2 instanceof Multipart)
            {
              // System.out.print("**This BodyPart is a nested
              // Multipart. ");
              Multipart mp2 = (Multipart) o2;

              int count2 = mp2.getCount();

              for (int k = 0; k < count2; k++)
              {
                b = mp2.getBodyPart(k);
                o2 = b.getContent();

                if ((o2 instanceof String))
                {
                  mEmailMessage.setContent(o2.toString());
View Full Code Here

         mbp1.setDataHandler(new DataHandler(ds));
         mbp1.setFileName(attachmentName);
         // mbp1.getContentType(); "application/octet-stream"

         // create the Multipart and add its parts to it
         Multipart mp = new MimeMultipart();
         mp.addBodyPart(mbp1);

         if (attachmentName2 != null) {
            MimeBodyPart mbp2 = new MimeBodyPart(); // "text/plain"
            mbp2.setText(attachment2, encoding);
            mbp2.setFileName(attachmentName2);
            mp.addBodyPart(mbp2);
         }

         // add the Multipart to the message
         message.setContent(mp);
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.