Package javax.mail

Examples of javax.mail.Address


        try {
            if (addstr.indexOf("@") < 0) {
                throw new AddressException();
            }

            Address address = null;

            if (name != null && name != Undefined.instance) {
                address = new InternetAddress(addstr,
                                          MimeUtility.encodeWord(name.toString()));
            } else {
View Full Code Here


                              Message.RecipientType type) throws Exception {
        if (addstr.indexOf("@") < 0) {
            throw new AddressException();
        }

        Address address = null;

        if (name != null && name != Undefined.instance) {
            address = new InternetAddress(addstr,
                                          MimeUtility.encodeWord(name.toString()));
        } else {
View Full Code Here

      {
        newMessageID = this.applyRule(rv, mesage[i], accountID, userID);

        /*** Modified By Shilpa to create/update a ticket out of an email***/

        Address from[] = mesage[i].getFrom();
        String strFrom = from[0].toString();

        String body = null;

        // get body part
View Full Code Here

    int messageID = 0;

    try
    {
      Address from[] = message.getFrom();

      // get the message's date and time
      long messageTime = (message.getSentDate()).getTime();
      java.sql.Timestamp messageDate = (java.sql.Timestamp)new java.sql.Timestamp(messageTime);

      cvdl.setSqlQuery("INSERT INTO emailmessage(MessageDate, MailFrom, Subject, Body, accountID , Priority, Headers, owner,Size) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");

      String mesgFrom = from[0].toString();
      mesgFrom = mesgFrom.replaceAll("\""," ");
      mesgFrom = mesgFrom.replaceAll("'"," ");
      mesgFrom = mesgFrom.trim();

      String[] DateHeader = message.getHeader("Date");
      Date receiveDate = new Date(DateHeader[0]);
      SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss");
      String receivedDate = formatter.format(receiveDate);

      if (receivedDate != null && !(receivedDate.equals("")))
      {
        cvdl.setString(1, receivedDate);
      }else{
        cvdl.setString(1, "CONCAT(CURRENT_DATE, CURRENT_TIME)");
      }

      cvdl.setString(2, mesgFrom);
      cvdl.setString(3, message.getSubject());

      String MsgBody = null;
      StringBuffer msgBody = new StringBuffer();


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

              if (o3 instanceof String)
              {
                if (mimeType3 != null &&
                    (mimeType3.toLowerCase().indexOf("text/plain") != -1 || mimeType3.toLowerCase().indexOf("text/html") != -1) &&
                    (disposition3==null ||( disposition3!=null && !disposition3.equals(Part.ATTACHMENT))))
                {
                  if (mimeType3.toLowerCase().indexOf("text/html") >= 0)
                  {
                    // HTML message body
                    msgBody.append(b2.getContent().toString());
                  }else{
                    // plain text part
                    msgBody.append(b2.getContent().toString());
                  }
                }

                if (! msgBody.toString().equals(""))
                {
                  break;
                }
              }   // end if (o3 instanceof String)
            }   // end for (int k = 0; k < countMultipart1; k++)
          }   // end if(o2 instanceof Multipart)
        }   // end for (int j = 0; j < countMultipart; j++)
      }   // end if (o instanceof String)

      MsgBody = msgBody.toString();

      if (MsgBody != null)
      {
        cvdl.setString(4,MsgBody);
      }else{
        cvdl.setString(4,"");
      }

      cvdl.setInt(5, accountID);

      // set priority field based on message X-Priority header.
      // if the X-Priority header is not set, or is unknown, then
      // set our database priority field to medium.
      if (mimeMessage.getHeader("X-Priority", "") != null)
      {
        if ((mimeMessage.getHeader("X-Priority", "")).equals("1"))
        {
          cvdl.setString(6, "HIGH");
        }else if ((mimeMessage.getHeader("X-Priority", "")).equals("5")){
          cvdl.setString(6, "LOW");
        }else{
          cvdl.setString(6, "MEDIUM");
        }
      }else{
        cvdl.setString(6, "MEDIUM");
      }

      // added for taking the header also
      Enumeration em = mimeMessage.getAllHeaderLines();

      StringBuffer ah = new StringBuffer();

      // loop through all the headers
      while (em.hasMoreElements())
      {
        String ch = (String)em.nextElement();
        ah.append(ch);
      }   // end while (em.hasMoreElements())

      if (ah.length() > 0)
      {
        cvdl.setString(7, ah.toString());
      }else{
        cvdl.setString(7, null);
      }

      cvdl.setInt(8, userID);

      long messageSize = mimeMessage.getSize();
      if (messageSize > 1024)
      {
        messageSize = messageSize / 1024;
      }else{
        messageSize = 1;
      }

      cvdl.setString(9, messageSize+"");

      cvdl.executeUpdate();

      messageID = cvdl.getAutoGeneratedKey();

      cvdl.clearParameters();

      if (messageID != 0)
      {
        Address arrayTo[] = message.getRecipients(Message.RecipientType.TO);
        Address arrayCc[] = message.getRecipients(Message.RecipientType.CC);
        Address arrayBcc[] = message.getRecipients(Message.RecipientType.BCC);

        if ((arrayTo != null) && (arrayTo.length != 0))
        {
          for (int i = 0; i < arrayTo.length; i++)
          {
View Full Code Here

    String host = config.getValue(Constants.CHAPTER_SYSTEM, mDestination
        .getName(), "Host");
    String subject = config.getValue(Constants.CHAPTER_SYSTEM, mDestination
        .getName(), "Subject");

    Address fromAddress;
    Address[] toAddresses;
    try
    {
      String address = null;
      Vector addressList = new Vector();
View Full Code Here

      try
      {
         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);
View Full Code Here

    Locale recLocale = I18nManager.getInstance().getLocaleOrDefault(recipientTO.getUser().getPreferences().getLanguage());
    String subject = subjectWriter.toString();
    String body = bodyWriter.toString() + MailHelper.getMailFooter(recLocale, sender) + "\n";
 
    // add sender to mail
    Address from, to;
    try {
      if (sender == null) {
        from = new InternetAddress(WebappHelper.getMailConfig("mailFrom"));
      } else {
        from = new InternetAddress(sender.getUser().getProperty(UserConstants.EMAIL, null));
View Full Code Here

   
    if (messageReady){
       Address[] addresses = message.getRecipients(MimeMessage.RecipientType.TO);
       if (addresses != null){
          for (int i = 0;i<addresses.length; i++) {
            Address aktAddress  = addresses[i]
           s += aktAddress.toString() + ",";
          }
       }
    }else{
       for (Iterator i = this.toList.listIterator(); i.hasNext();) {
         s += i.next() + ",";
View Full Code Here

   
    if (messageReady){
       Address[] addresses = message.getRecipients(MimeMessage.RecipientType.CC);
       if (addresses != null){
          for (int i = 0;i<addresses.length; i++) {
            Address aktAddress  = addresses[i]
           s += aktAddress.toString() + ",";
          }
       }
    }else{
       for (Iterator i = this.ccList.listIterator(); i.hasNext();) {
         s += i.next() + ",";
View Full Code Here

   
    if (messageReady){
       Address[] addresses = message.getRecipients(MimeMessage.RecipientType.BCC);
       if (addresses != null){
          for (int i = 0;i<addresses.length; i++) {
            Address aktAddress  = addresses[i]
           s += aktAddress.toString() + ",";
          }
       }
    }else{
       for (Iterator i = this.bccList.listIterator(); i.hasNext();) {
         s += i.next() + ",";
View Full Code Here

TOP

Related Classes of javax.mail.Address

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.