Package javax.mail.internet

Examples of javax.mail.internet.MimeMessage


              sContentType.toUpperCase().startsWith("MULTIPART/RELATED") ||
              sContentType.toUpperCase().startsWith("MULTIPART/SIGNED")) {
              try {
                ByteArrayInputStream byInStrm = new ByteArrayInputStream(byOutPart.toByteArray());

                MimeMessage oForwarded = new MimeMessage (((DBStore) getStore()).getSession(), byInStrm);

                saveMimeParts (oForwarded, sMsgCharSeq, getPartsBoundary(oForwarded), sMsgGuid, sMsgId, iPgMessage, iOffset+iParts);

                byInStrm.close();
                byInStrm = null;
View Full Code Here


  // ---------------------------------------------------------------------------

  public int importMbox(String sMboxFilePath)
    throws FileNotFoundException, IOException, MessagingException {

    MimeMessage oMsg;
    InputStream oMsgStrm;
    Session oSession = ((DBStore)getStore()).getSession();
    MboxFile oInputMbox = new MboxFile(sMboxFilePath, MboxFile.READ_ONLY);

    final int iMsgCount = oInputMbox.getMessageCount();

    for (int m=0; m<iMsgCount; m++) {
      oMsgStrm = oInputMbox.getMessageAsStream(m);
      oMsg = new MimeMessage(oSession, oMsgStrm);
      appendMessage(oMsg);
      oMsgStrm.close();
    }

    oInputMbox.close();
View Full Code Here

   * @throws SQLException
   */
  public void reindexMbox(String sMboxFilePath)
    throws FileNotFoundException, IOException, MessagingException, SQLException {

    MimeMessage oMsg;
    InputStream oMsgStrm;
    int iMsgCount;
    HeadersHelper oHlpr;
    RecipientsHelper oRecps;
    BigDecimal dPgMessage;
    String sGuMimeMsg;
    String sMessageID;
    String sMsgCharSeq;
    String sContentMD5;
    int iSize;
    Integer oSize;
    MboxFile oInputMbox = null;
  JDCConnection oConn = null;
 
    if (DebugFile.trace) {
      DebugFile.writeln("Begin DBFolder.reindexMbox("+sMboxFilePath+")");
      DebugFile.incIdent();
    }

    try {
      ByteArrayOutputStream byOutStrm = null;
      Session oSession = ((DBStore)getStore()).getSession();
      String sGuWorkArea = ((DBStore)getStore()).getUser().getString(DB.gu_workarea);
      String sGuFolder = getCategoryGuid();
      oInputMbox = new MboxFile(sMboxFilePath, MboxFile.READ_ONLY);
      DBSubset oMsgs = new DBSubset (DB.k_mime_msgs, DB.gu_mimemsg+","+DB.gu_workarea, DB.gu_category+"=?", 1000);
      oConn = getConnection();
      iMsgCount = oMsgs.load(oConn, new Object[]{sGuFolder});

      if (DebugFile.trace) DebugFile.writeln(String.valueOf(iMsgCount)+" indexed messages");

      for (int m=0; m<iMsgCount; m++)
        DBMimeMessage.delete(oConn, sGuFolder, oMsgs.getString(0,m));

      iMsgCount = oInputMbox.getMessageCount();

      if (DebugFile.trace) DebugFile.writeln(String.valueOf(iMsgCount)+" stored messages");

      for (int m=0; m<iMsgCount; m++) {
        sGuMimeMsg = Gadgets.generateUUID();
        oMsgStrm = oInputMbox.getMessageAsStream(m);
        oMsg = new MimeMessage(oSession, oMsgStrm);
        oHlpr = new HeadersHelper(oMsg);
        oRecps = new RecipientsHelper(oMsg);
        dPgMessage = new BigDecimal(m);
        sMessageID = oHlpr.decodeMessageId(sGuMimeMsg);
        sMsgCharSeq = DBMimeMessage.source(oMsg, "ISO8859_1");
        sContentMD5 = oHlpr.getContentMD5();
        if (null==sContentMD5) sContentMD5 = HeadersHelper.computeContentMD5(sMsgCharSeq.getBytes());
        iSize = ((iOpenMode&MODE_MBOX)!=0) ? sMsgCharSeq.length() : oMsg.getSize();
        oSize = (iSize>=0 ? new Integer(iSize) : null);
        byOutStrm = getBodyAsStream(oMsg);

        indexMessage(Gadgets.generateUUID(), sGuWorkArea, oMsg, oSize,
                   ((iOpenMode&MODE_MBOX)!=0) ? new BigDecimal(oInputMbox.getMessagePosition(m)) : null,
View Full Code Here

          throw new MessagingException(nspe.getMessage(), nspe);
        }
      } // fi (Session.getInstance())
    } // fi (oMailSession)

    MimeMessage oMsg;
    InternetAddress oFrom, oTo;
    MimeMultipart oAltParts = new MimeMultipart("alternative");
   
    // Set alternative plain/text part to avoid spam filters as much as possible
    MimeBodyPart oMsgTextPart = new MimeBodyPart();
  oMsgTextPart.setText("This message is HTML, but your e-mail client is not capable of rendering HTML messages", "UTF-8", "plain");

    MimeBodyPart oMsgBodyPart = new MimeBodyPart();
 
    try {
      if (null==getParameter("tx_sender"))
        oFrom = new InternetAddress(getParameter("tx_from"));
      else
        oFrom = new InternetAddress(getParameter("tx_from"), getParameter("tx_sender"));

      if (DebugFile.trace) DebugFile.writeln("to: " + oAtm.getStringNull(DB.tx_email, "ERROR Atom[" + String.valueOf(oAtm.getInt(DB.pg_atom)) + "].tx_email is null!"));

      oTo = new InternetAddress(oAtm.getString(DB.tx_email), oAtm.getStringNull(DB.tx_name,"") + " " + oAtm.getStringNull(DB.tx_surname,""));
    }
    catch (AddressException adre) {
      if (DebugFile.trace) DebugFile.writeln("AddressException " + adre.getMessage() + " job " + getString(DB.gu_job) + " atom " + String.valueOf(oAtm.getInt(DB.pg_atom)));

      oFrom = null;
      oTo = null;

      throw new MessagingException ("AddressException " + adre.getMessage() + " job " + getString(DB.gu_job) + " atom " + String.valueOf(oAtm.getInt(DB.pg_atom)));
    }

    if (DebugFile.trace) DebugFile.writeln("new MimeMessage([Session])");

    oMsg = new MimeMessage(oMailSession);

    oMsg.setSubject(getParameter("tx_subject"));

    oMsg.setFrom(oFrom);

    if (DebugFile.trace) DebugFile.writeln("MimeMessage.addRecipient(MimeMessage.RecipientType.TO, " + oTo.getAddress());

    oMsg.addRecipient(MimeMessage.RecipientType.TO, oTo);

    String sSrc = null, sCid = null;

    try {
   
    // Insert Web Beacon just before </BODY> tag
    if (Yes.equals(getParameter("bo_webbeacon"))) {
      int iEndBody = Gadgets.indexOfIgnoreCase(oReplaced, "</body>", 0);
      if (iEndBody>0) {
        String sWebBeaconDir = getProperty("webbeacon");       
        if (sWebBeaconDir==null) {
          sWebBeaconDir = Gadgets.chomp(getParameter("webserver"),'/')+"hipermail/";
        } else if (sWebBeaconDir.trim().length()==0) {
          sWebBeaconDir = Gadgets.chomp(getParameter("webserver"),'/')+"hipermail/";
        }
        oReplaced = oReplaced.substring(0, iEndBody)+"<img src=\""+Gadgets.chomp(sWebBeaconDir,'/')+"web_beacon.jsp?gu_job="+getString(DB.gu_job)+"&pg_atom="+String.valueOf(oAtm.getInt(DB.pg_atom))+"&gu_company="+oAtm.getStringNull(DB.gu_company,"")+"&gu_contact="+oAtm.getStringNull(DB.gu_contact,"")+"&tx_email="+oAtm.getStringNull(DB.tx_email,"")+"\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" />"+oReplaced.substring(iEndBody);         
      } // fi </body>
    } // fi (bo_webbeacon)
     
      // Images may be attached into message or be absolute http source references
      if (Yes.equals(getParameter("bo_attachimages"))) {

        if (DebugFile.trace) DebugFile.writeln("BodyPart.setText("+oReplaced.replace('\n',' ')+",UTF-8,html)");

        oMsgBodyPart.setText(oReplaced, "UTF-8", "html");

        // Create a related multi-part to combine the parts
        MimeMultipart oRelatedMultiPart = new MimeMultipart("related");
        oRelatedMultiPart.addBodyPart(oMsgBodyPart);

        Iterator<String> oImgs = oDocumentImages.keySet().iterator();

        while (oImgs.hasNext()) {
          MimeBodyPart oImgBodyPart = new MimeBodyPart();

          sCid = oImgs.next();
          sSrc = oDocumentImages.get(sCid);

          if (sSrc.startsWith("www."))
            sSrc = "http://" + sSrc;

          if (sSrc.startsWith("http://") || sSrc.startsWith("https://")) {
            oImgBodyPart.setDataHandler(new DataHandler(new URL(sSrc)));
          }
          else {
            oImgBodyPart.setDataHandler(new DataHandler(new FileDataSource(sSrc)));
          }

          oImgBodyPart.setContentID(sCid);
          oImgBodyPart.setDisposition(oImgBodyPart.INLINE);
          oImgBodyPart.setFileName(sCid);

          // Add part to multi-part
          oRelatedMultiPart.addBodyPart(oImgBodyPart);
        } // wend

        MimeBodyPart oTextHtmlRelated = new MimeBodyPart();
        oTextHtmlRelated.setContent(oRelatedMultiPart);

    oAltParts.addBodyPart(oMsgTextPart);
    oAltParts.addBodyPart(oTextHtmlRelated);

      MimeMultipart oSentMsgParts = new MimeMultipart("mixed");
     MimeBodyPart oMixedPart = new MimeBodyPart();
       
        oMixedPart.setContent(oAltParts);
        oSentMsgParts.addBodyPart(oMixedPart);
       
        oMsg.setContent(oSentMsgParts);
      }

      else {

        if (DebugFile.trace) DebugFile.writeln("BodyPart.setText("+oReplaced.replace('\n',' ')+",UTF-8,html)");

    oMsgBodyPart.setText(oReplaced, "UTF-8", "html");

    oAltParts.addBodyPart(oMsgTextPart);
    oAltParts.addBodyPart(oMsgBodyPart);

        oMsg.setContent(oAltParts);

      }

      oMsg.saveChanges();

      if (DebugFile.trace) DebugFile.writeln("Transport.sendMessage([MimeMessage], MimeMessage.getAllRecipients())");

      oMailTransport.sendMessage(oMsg, oMsg.getAllRecipients());

      // ************************************************************
      // Decrement de count of atoms peding of processing at this job
      iPendingAtoms--;
    }
View Full Code Here

  public String getType() {
    return "mail";
  }

  public void deliver(T mailMsg) throws NotificationException {
    MimeMessage mimeMsg = mailSender.createMimeMessage();
    try {
      if (null == mailMsg.getSendAt()) {
        mimeMsg.setSentDate(new Date());
      } else {
        mimeMsg.setSentDate(mailMsg.getSendAt());
      }
      MimeMessageHelper messageHelper = null;
      String encoding = StringUtils.substringAfter(mailMsg.getContentType(), "charset=");
      if (StringUtils.isEmpty(encoding)) {
        messageHelper = new MimeMessageHelper(mimeMsg);
View Full Code Here

        properties.put("mail.user", JManageProperties.getAlertEmailFromName());
        properties.put("mail.host", JManageProperties.getEmailHost());
        properties.put("mail.from", JManageProperties.getAlertEmailFrom());
        properties.put("mail.transport.protocol", "smtp");
        Session session = Session.getInstance(properties);
        MimeMessage message = new MimeMessage(session);
        message.addRecipients(Message.RecipientType.TO, to);
        message.setSubject(subject);
        message.setText(content);
        Transport.send(message);
    }
View Full Code Here

        if (!FACTORY_TYPE.equals(reference.getClassName())) {
            return null;
        }

        // Build Mimemessage wrapping a session object
        MimeMessage mimeMessage = new MimeMessage(Session.getInstance(getSessionProperties(reference),
                getAuthenticator(reference)));

        // Field 'to'
        Address[] toRecipients = getObject(reference, TO_RECIPIENTS);
        if (toRecipients != null) {
            mimeMessage.setRecipients(Message.RecipientType.TO, toRecipients);
        }

        // Field 'cc'
        Address[] ccRecipients = getObject(reference, CC_RECIPIENTS);
        if (ccRecipients != null) {
            mimeMessage.setRecipients(Message.RecipientType.CC, ccRecipients);
        }

        // Field 'bcc'
        Address[] bccRecipients = getObject(reference, BCC_RECIPIENTS);
        if (bccRecipients != null) {
            mimeMessage.setRecipients(Message.RecipientType.BCC, bccRecipients);
        }

        // Field 'subject'
        String mailSubject = getString(reference, SUBJECT);
        if (mailSubject != null) {
            mimeMessage.setSubject(mailSubject);
        }

        // Build object and return it
        MimePartDataSource mimePartDS = new MimePartDataSource(mimeMessage);
        return mimePartDS;
View Full Code Here

      {
         Session session = (Session) new InitialContext().lookup("java:/Mail");
         // create a message
         //
         Address replyToList[] = { replyTo };
         Message newMessage = new MimeMessage(session);
         newMessage.setFrom(from);
         newMessage.setReplyTo(replyToList);
         newMessage.setRecipients(Message.RecipientType.TO, to);
         newMessage.setSubject(subject);
         newMessage.setSentDate(new java.util.Date());
         newMessage.setText(message);

         // Send newMessage
          //
          Transport transport = session.getTransport();
          transport.connect();
View Full Code Here

                  .getProperty("mail.smtp.user", ""),
                  properties.getProperty(
                      "mail.smtp.password", ""));
            }
          });
      MimeMessage message = new MimeMessage(session);
      message.setFrom(new InternetAddress(sender));
      message.setReplyTo(new InternetAddress[] { new InternetAddress(
          sender) });
      message.setRecipients(Message.RecipientType.TO,
          InternetAddress.parse(recipients, false));
      message.setSubject(subject, "utf-8");
      message.setSentDate(new Date());
      message.setHeader("Content-Type", "text/plain; charset=\"utf-8\"");
      message.setHeader("Content-Transfer-Encoding", "quoted-printable");
      message.setText(text, "utf-8");
      Transport.send(message);
    }
  }
View Full Code Here

            public void doEvent(FilterChain chain, Event e) {
                MailboxAddress from = MailboxAddress.parse(event.getFrom());
                MailboxAddress recip = MailboxAddress.parse(event.getRecipient());

                MimeMessage mm = parseInput(data);

                Mailbox recipMailbox = resourceFactory.getMailbox(recip);
                log.debug("recipient is known to us, so store: " + recip);
                storeMail(recipMailbox,mm);
View Full Code Here

TOP

Related Classes of javax.mail.internet.MimeMessage

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.