Examples of MimeBodyPart


Examples of javax.mail.internet.MimeBodyPart

        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

Examples of javax.mail.internet.MimeBodyPart

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

Examples of javax.mail.internet.MimeBodyPart

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

Examples of javax.mail.internet.MimeBodyPart

        if(smtpPort>0 && smtpPort!=25)
            mailProperties.put("mail.smtp.port", String.valueOf(smtpPort));
        mailProperties.put("mail.smtp.auth", "true"); //����smtp��֤���ܹؼ���һ��
        mailSession = Session.getDefaultInstance(mailProperties, this);
        mailMessage = new MimeMessage(mailSession);
        messageBodyPart = new MimeBodyPart();
    }
View Full Code Here

Examples of javax.mail.internet.MimeBodyPart

            }

            //����htmlҳ���ϵ�ͼƬ�������£�
            private void processHtmlImage(String mailContent) throws MessagingException {
                for (int i = 0; i < arrayList1.size(); i++) {
                    messageBodyPart = new MimeBodyPart();
                    DataSource source = new FileDataSource((String) arrayList1.get(i));
                    messageBodyPart.setDataHandler(new DataHandler(source));
                    String contentId = "<" + (String) arrayList2.get(i) + ">";
                    messageBodyPart.setHeader("Content-ID", contentId);
                    messageBodyPart.setFileName((String) arrayList1.get(i));
View Full Code Here

Examples of javax.mail.internet.MimeBodyPart

     * �����ʼ����͸���
     * @param attachmentName
     * @throws MessagingException
     */
    public void setAttachments(String attachmentName) throws MessagingException {
        messageBodyPart = new MimeBodyPart();
        DataSource source = new FileDataSource(attachmentName);
        messageBodyPart.setDataHandler(new DataHandler(source));
        int index = attachmentName.lastIndexOf(File.separator);
        String attachmentRealName = attachmentName.substring(index + 1);
        messageBodyPart.setFileName(attachmentRealName);
View Full Code Here

Examples of javax.mail.internet.MimeBodyPart

      if (subject != null)
      {
        msg.setSubject(subject);
      }

      MimeBodyPart part = new MimeBodyPart();

      StringBuffer sbuf = new StringBuffer();
     
      Formatter f = getFormatter();
     
      String head = f.getHead(this);

      if (head != null)
      {
        sbuf.append(head);
      }

      int len = cb.length();

      for (int i = 0; i < len; i++)
      {
        LogRecord record = cb.get();
        sbuf.append(getFormatter().format(record));
      }

      String tail = getFormatter().getTail(this);

      if (tail != null)
      {
        sbuf.append(tail);
      }

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

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

Examples of javax.mail.internet.MimeBodyPart

        }
      }

      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:");
      e.printStackTrace();
View Full Code Here

Examples of javax.mail.internet.MimeBodyPart

      }

      message.setFrom(new InternetAddress(from));

      message.setSubject(subject);
      BodyPart messageBodyPart        = new MimeBodyPart();

      //Added by Ryan Grier <ryan@centraview.com>
      //Need to send email as plain text if
      //it contains no html content.
      String messageContext = "text/plain";

//   Modified by Deepa
//  User Preferences value will decide content type of the email. ie. Plain text or Html text

  InitialContext ic = CVUtility.getInitialContext();
  PreferenceLocalHome home  = (PreferenceLocalHome)ic.lookup("local/Preference");
  PreferenceLocal localPref =  home.create();
  localPref.setDataSource(this.dataSource);

  UserPrefererences userPref = localPref.getUserPreferences(userId);


  if(userPref != null)
  if (userPref.getContentType() != null && userPref.getContentType().equals("PLAIN"))
  {
    messageContext = "text/plain";
  }
  else if ( userPref.getContentType() != null && userPref.getContentType().equals("HTML"))
  {
    messageContext = "text/html";
  }

  if(mailmessage.getContentType() != null && mailmessage.getContentType().equals("HTML") ){
    messageContext = "text/html";
  }

/*    if ((body.indexOf("<") > -1) && (body.indexOf(">") > -1))
      {
        messageContext = "text/html";
      } //end of if statement ((body.indexOf("<") > -1) && (body.indexOf(">") > -1))
      else if ((body.indexOf("&lt;") > -1) && (body.indexOf("&gt;") > -1))
      {
        messageContext = "text/html";
      } //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
View Full Code Here

Examples of javax.mail.internet.MimeBodyPart

            }
          }

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