Package javax.mail.internet

Examples of javax.mail.internet.InternetAddress


  /** */
  private void testEightBitMessage(String body, String charset) throws Exception
  {
    MimeMessage message = new MimeMessage(this.session);
    message.addRecipient(Message.RecipientType.TO, new InternetAddress("anyone@anywhere.com"));
    message.setFrom(new InternetAddress("someone@somewhereelse.com"));
    message.setSubject("hello");
    message.setText(body, charset);
    message.setHeader("Content-Transfer-Encoding", "8bit");

    Transport.send(message);
View Full Code Here


  {
    byte[] body = new byte[64];
    new Random().nextBytes(body);

    MimeMessage message = new MimeMessage(this.session);
    message.addRecipient(Message.RecipientType.TO, new InternetAddress("anyone@anywhere.com"));
    message.setFrom(new InternetAddress("someone@somewhereelse.com"));
    message.setSubject("hello");
    message.setHeader("Content-Transfer-Encoding", "8bit");
    message.setDataHandler(new DataHandler(new ByteArrayDataSource(body, "application/octet-stream")));

    Transport.send(message);
View Full Code Here

                             DB.tx_md5+","+DB.de_mimemsg+","+DB.tx_subject+","+
                             DB.dt_sent+","+DB.bo_answered+","+DB.bo_deleted+","+
                             DB.bo_draft+","+DB.bo_flagged+","+DB.bo_recent+","+
                             DB.bo_seen+","+DB.tx_email_from+","+DB.tx_email_reply+","+
                             DB.nm_from+","+DB.by_content;
    InternetAddress oFrom = null, oReply = null;
    MimeMultipart oParts = new MimeMultipart();
  JDCConnection oConn = null;
 
    try {
      oConn = getConnection();
      switch (IdType) {
        case 1:
          sSQL = "SELECT "+sColList+" FROM " + DB.k_mime_msgs + " WHERE " + DB.gu_mimemsg + "=?";
          if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement("+sSQL+")");

          oStmt = oConn.prepareStatement(sSQL, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
          oStmt.setString(1, sMsgId);
          break;
        case 2:
          sSQL = "SELECT "+sColList+" FROM " + DB.k_mime_msgs + " WHERE " + DB.id_message + "=?";
          if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement("+sSQL+")");

          oStmt = oConn.prepareStatement(sSQL, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
          oStmt.setString(1, sMsgId);
          break;
        case 3:
          sSQL = "SELECT "+sColList+" FROM " + DB.k_mime_msgs + " WHERE " + DB.pg_message + "=?";
          if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement("+sSQL+")");

          oStmt = oConn.prepareStatement(sSQL, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
          oStmt.setBigDecimal(1, new java.math.BigDecimal(sMsgId));
          break;
      }

      if (DebugFile.trace) DebugFile.writeln("ResultSet = PreparedStatement.executeQuery("+sSQL+")");

      oRSet = oStmt.executeQuery();

      if (oRSet.next()) {
        sMsgGuid = oRSet.getString(1);
        sContentId = oRSet.getString(2);

        if (DebugFile.trace) {
          DebugFile.writeln("gu_mimemsg="+sMsgGuid);
          DebugFile.writeln("id_message="+sContentId);
        }
       
        sMsgDisposition = oRSet.getString(3);
        sMsgMD5 = oRSet.getString(4);
        sMsgDesc = oRSet.getString(5);
        sMsgSubject = oRSet.getString(6);
        tsSent = oRSet.getTimestamp(7);
        iAnswered=oRSet.getShort(8);
        iDeleted=oRSet.getShort(9);
        iDraft=oRSet.getShort(10);
        iFlagged=oRSet.getShort(11);
        iRecent=oRSet.getShort(12);
        iSeen=oRSet.getShort(13);
        sMsgFrom = oRSet.getString(14);
        sReplyTo = oRSet.getString(15);
        sDisplayName = oRSet.getString(16);

        if (DebugFile.trace) DebugFile.writeln("ResultSet.getBinaryStream("+DB.by_content+")");

        InputStream oLongVarBin = oRSet.getBinaryStream(17);

        if (!oRSet.wasNull()) {
          if (DebugFile.trace) DebugFile.writeln("MimeMultipart.addBodyPart(new MimeBodyPart(InputStream)");
          oParts.addBodyPart(new MimeBodyPart(oLongVarBin));
        }

        oRSet.close();
        oRSet = null;

        oRetVal = new DBMimeMessage(this, sMsgGuid);

        oRetVal.setContentID(sContentId);
        oRetVal.setDisposition(sMsgDisposition);
        oRetVal.setContentMD5(sMsgMD5);
        oRetVal.setDescription(sMsgDesc);

        if (sMsgSubject!=null) {
          if (sMsgSubject.length()>0) {
            if (DebugFile.trace) DebugFile.writeln("tx_subject="+sMsgSubject);
            oRetVal.setSubject(sMsgSubject);
          }
        }

        oRetVal.setSentDate(tsSent);
        oRetVal.setFlag(Flags.Flag.ANSWERED, iAnswered!=0);
        oRetVal.setFlag(Flags.Flag.DELETED, iDeleted!=0);
        oRetVal.setFlag(Flags.Flag.DRAFT, iDraft!=0);
        oRetVal.setFlag(Flags.Flag.FLAGGED, iFlagged!=0);
        oRetVal.setFlag(Flags.Flag.RECENT, iRecent!=0);
        oRetVal.setFlag(Flags.Flag.SEEN, iSeen!=0);

        if (sMsgFrom!=null) {
          if (DebugFile.trace) DebugFile.writeln("from: "+sMsgFrom);
          if (null==sDisplayName)
            oFrom = new InternetAddress(sMsgFrom);
          else
            oFrom = new InternetAddress(sMsgFrom, sDisplayName);
          oRetVal.setFrom(oFrom);
        }

        if (sReplyTo!=null) {
          if (DebugFile.trace) DebugFile.writeln("reply to: "+sReplyTo);
          oReply = new InternetAddress(sReplyTo);
          oRetVal.setReplyTo(new Address[]{oReply});
        }

        oRetVal.setRecipients(Message.RecipientType.TO, oRetVal.getRecipients(Message.RecipientType.TO));
        oRetVal.setRecipients(Message.RecipientType.CC, oRetVal.getRecipients(Message.RecipientType.CC));
View Full Code Here

    try {
      oAddr = oConn.prepareStatement(sSQL, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
      ResultSet oRSet;

      InternetAddress oInetAdr;
      String sTxEmail, sGuCompany, sGuContact, sTxName, sTxSurname1, sTxSurname2, sTxPersonal;

      // Get From address and keep them into pFrom properties

      if (oFrom!=null) {
        oAddr.setString(1, oFrom.getAddress());
        oAddr.setString(2, sGuWorkArea);
        oAddr.setString(3, oFrom.getAddress());
        oAddr.setString(4, oFrom.getAddress());
        oAddr.setString(5, oFrom.getAddress());
        oAddr.setString(6, sGuWorkArea);

        oRSet = oAddr.executeQuery();
        if (oRSet.next()) {
          sGuContact = oRSet.getString(1);
          if (oRSet.wasNull()) sGuContact = "null";
          sGuCompany = oRSet.getString(2);
          if (oRSet.wasNull()) sGuCompany = "null";

          if (sGuCompany.equals("****************************USER")) {
            sTxName = oRSet.getString(3);
            if (oRSet.wasNull()) sTxName = "";
            sTxSurname1 = oRSet.getString(4);
            if (oRSet.wasNull()) sTxSurname1 = "";
            sTxSurname2 = oRSet.getString(4);
            if (oRSet.wasNull()) sTxSurname2 = "";
            sTxPersonal = Gadgets.left(sTxName+" "+sTxSurname1+" "+sTxSurname2, 254).replace(',',' ').trim();
          }
          else
            sTxPersonal = "null";

          if (DebugFile.trace) DebugFile.writeln("from "+sGuContact+","+sGuCompany+","+sTxPersonal);
          pFrom.put(oFrom.getAddress(), sGuContact+","+sGuCompany+","+sTxPersonal);
        }
        else
          pFrom.put(oFrom.getAddress(), "null,null,null");

      oRSet.close();
      } // fi (oFrom)

      if (DebugFile.trace) DebugFile.writeln("from count = " + pFrom.size());

      // Get TO address and keep them into pTo properties

      if (oTo!=null) {
        for (int t=0; t<oTo.length; t++) {
          oInetAdr = (InternetAddress) oTo[t];
          sTxEmail = Gadgets.left(oInetAdr.getAddress(), 254);

          oAddr.setString(1, sTxEmail);
          oAddr.setString(2, sGuWorkArea);
          oAddr.setString(3, sTxEmail);
          oAddr.setString(4, sTxEmail);
          oAddr.setString(5, sTxEmail);
          oAddr.setString(6, sGuWorkArea);

          oRSet = oAddr.executeQuery();
          if (oRSet.next()) {
            sGuContact = oRSet.getString(1);
            if (oRSet.wasNull()) sGuContact = "null";
            sGuCompany = oRSet.getString(2);
            if (oRSet.wasNull()) sGuCompany = "null";
            if (sGuCompany.equals("****************************USER")) {
              sTxName = oRSet.getString(3);
              if (oRSet.wasNull()) sTxName = "";
              sTxSurname1 = oRSet.getString(4);
              if (oRSet.wasNull()) sTxSurname1 = "";
              sTxSurname2 = oRSet.getString(4);
              if (oRSet.wasNull()) sTxSurname2 = "";
              sTxPersonal = Gadgets.left(sTxName+" "+sTxSurname1+" "+sTxSurname2, 254).replace(',',' ').trim();
            }
            else
              sTxPersonal = "null";

            pTo.put(sTxEmail, sGuContact+","+sGuCompany+","+sTxPersonal);
          } // fi (oRSet.next())
          else
            pTo.put(sTxEmail, "null,null,null");

          oRSet.close();
        } // next (t)
      } // fi (oTo)

      if (DebugFile.trace) DebugFile.writeln("to count = " + pTo.size());

      // Get CC address and keep them into pTo properties

      if (oCC!=null) {
        for (int c=0; c<oCC.length; c++) {
          oInetAdr = (InternetAddress) oCC[c];
          sTxEmail = Gadgets.left(oInetAdr.getAddress(), 254);

          oAddr.setString(1, sTxEmail);
          oAddr.setString(2, sGuWorkArea);
          oAddr.setString(3, sTxEmail);
          oAddr.setString(4, sTxEmail);
          oAddr.setString(5, sTxEmail);
          oAddr.setString(6, sGuWorkArea);

          oRSet = oAddr.executeQuery();
          if (oRSet.next()) {
            sGuContact = oRSet.getString(1);
            if (oRSet.wasNull()) sGuContact = "null";
            sGuCompany = oRSet.getString(2);
            if (oRSet.wasNull()) sGuCompany = "null";
            if (sGuCompany.equals("****************************USER")) {
              sTxName = oRSet.getString(3);
              if (oRSet.wasNull()) sTxName = "";
              sTxSurname1 = oRSet.getString(4);
              if (oRSet.wasNull()) sTxSurname1 = "";
              sTxSurname2 = oRSet.getString(4);
              if (oRSet.wasNull()) sTxSurname2 = "";
              sTxPersonal = Gadgets.left(sTxName+" "+sTxSurname1+" "+sTxSurname2, 254).replace(',',' ').trim();
            }
            else
              sTxPersonal = "null";

            pCC.put(sTxEmail, sGuContact+","+sGuCompany+","+sTxPersonal);
          } // fi (oRSet.next())
          else
            pCC.put(sTxEmail, "null,null,null");

          oRSet.close();
        } // next (c)
      } // fi (oCC)

      if (DebugFile.trace) DebugFile.writeln("cc count = " + pCC.size());

      // Get BCC address and keep them into pTo properties

      if (oBCC!=null) {
        for (int b=0; b<oBCC.length; b++) {
          oInetAdr = (InternetAddress) oBCC[b];
          sTxEmail = Gadgets.left(oInetAdr.getAddress(), 254);

          oAddr.setString(1, sTxEmail);
          oAddr.setString(2, sGuWorkArea);
          oAddr.setString(3, sTxEmail);
          oAddr.setString(4, sTxEmail);
View Full Code Here

        }
      } // 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;
View Full Code Here

        if (null==oDraft) throw new MessagingException("DBFolder.getMessageByGuid() Message "+sMsgId+" not found");

        oHeaders = oOutBox.getMessageHeaders(sMsgId);
        if (null==oHeaders) throw new MessagingException("DBFolder.getMessageHeaders() Message "+sMsgId+" not found");
        if (null==oHeaders.get(DB.nm_from))
          aFrom = new InternetAddress[]{new InternetAddress(oHeaders.getProperty(DB.tx_email_from))};
        else
          aFrom = new InternetAddress[]{new InternetAddress(oHeaders.getProperty(DB.tx_email_from),
                                                            oHeaders.getProperty(DB.nm_from))};

        if (DebugFile.trace) DebugFile.writeln("tx_email_reply="+oHeaders.getProperty(DB.tx_email_reply));

        aReply = new InternetAddress[]{new InternetAddress(oHeaders.getProperty(DB.tx_email_reply, oHeaders.getProperty(DB.tx_email_from)))};

        sBody = oDraft.getText();
        if (DebugFile.trace) {
          if (null==sBody)
            DebugFile.writeln("Message body: null");
View Full Code Here

      if (!oAtm.isNull(DB.tx_email)) {
        if (DebugFile.trace) DebugFile.writeln("tx_email="+oAtm.getString(DB.tx_email));
        String sSanitizedEmail = MailMessage.sanitizeAddress(oAtm.getString(DB.tx_email));
        if (DebugFile.trace) DebugFile.writeln("sanitized tx_email="+sSanitizedEmail);
        // An AddressException can be thrown here even after sanitizing the e-mail address
        InternetAddress oRec = DBInetAddr.parseAddress(sSanitizedEmail);

    // No blacklisted e-mails allowed to pass through
      if (aBlackList==null) {
        bBlackListed = false;
      } else {
View Full Code Here

            body.append( " Login: " + u.getId(  ) + "\n" );
            body.append( " Password: " + u.getPassword(  ) + "\n\n" );

            /* Send the message */
            MailService mailer = ( MailService ) ctx.getService( MailService.NAME );
            mailer.send( null, new Address[] { new InternetAddress( u.getEmail(  ) ) }, subject, body.toString(), MailService.MIME_TEXT );
        }
        catch ( UserNotFoundException u )
        {
            ctx.getLog(  ).warn( email + " not found", u );
        }
View Full Code Here

                for (MailAddress mail : mimePart.getMailAddresses()) {

                    // Build address object from the string
                    Address address = null;
                    try {
                        address = new InternetAddress(mail.getName());
                    } catch (AddressException e) {
                        throw new EZBComponentException("Cannot build an internet address with given value '" + mail.getName()
                                + "'.", e);
                    }
View Full Code Here

    if (StringUtils.isEmpty(address)) return Collections.emptyList();
    try {
      InternetAddress[] parsed = InternetAddress.parse(address);
      List<InternetAddress> returned = CollectUtils.newArrayList();
      for (InternetAddress raw : parsed) {
        returned.add((encoding != null ? new InternetAddress(raw.getAddress(), raw.getPersonal(),
            encoding) : raw));
      }
      return returned;
    } catch (Exception ex) {
      throw new RuntimeException("Failed to parse embedded personal name to correct encoding", ex);
View Full Code Here

TOP

Related Classes of javax.mail.internet.InternetAddress

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.