Package javax.mail.internet

Examples of javax.mail.internet.InternetAddress


   public void sendEmail(String from, String to, String subject, String body)
         throws AddressException, MessagingException {
      Message message = getMessage();
      try {
         message.setFrom(new InternetAddress(from));
         InternetAddress tos[] = new InternetAddress[1];
         tos[0] = new InternetAddress(to);
         message.setRecipients(Message.RecipientType.TO, tos);
         message.setSubject(subject);
         message.setContent(body, "text/plain");
      } catch (MessagingException e) {
         throw e;
View Full Code Here


      send(message);
   }

   public void sendEmail(String from, String to, String subject, String body,
         String encoding) throws AddressException, MessagingException {
      sendEmail(new InternetAddress(from), new InternetAddress(to), subject,
            body, encoding);
   }
View Full Code Here

         String subject, String body, String encoding) throws AddressException,
         MessagingException {
      MimeMessage message = new MimeMessage(getSession());
      try {
         message.setFrom(from);
         InternetAddress tos[] = new InternetAddress[1];
         tos[0] = to;
         message.setRecipients(Message.RecipientType.TO, tos);
         message.setSubject(subject, encoding);
         message.setText(body, encoding); // is automatically "text/plain"
      } catch (MessagingException e) {
View Full Code Here

         String attachmentName2, String attachment2, String encoding)
         throws XmlBlasterException {
      try {
         MimeMessage message = new MimeMessage(getSession());
         message.setFrom(from);
         InternetAddress tos[] = new InternetAddress[1];
         tos[0] = to;
         message.setRecipients(Message.RecipientType.TO, tos);
         message.setSubject(subject, encoding);

         // MimeBodyPart mbp1 = new MimeBodyPart(attachment);
View Full Code Here

      this.content = null;
   }
  
   private InternetAddress toInternetAddress(String address) throws IllegalArgumentException {
      try {
         return new InternetAddress(address);
      } catch (AddressException e) {
         throw new IllegalArgumentException("Illegal email address '" + address + "': " + e.toString());
      }
   }
View Full Code Here

      // TO
      if ((a = m.getRecipients(Message.RecipientType.TO)) != null) {
         for (int j = 0; j < a.length; j++) {
            pr("TO: " + a[j].toString(), level);
            InternetAddress ia = (InternetAddress) a[j];
            if (ia.isGroup()) {
               InternetAddress[] aa = ia.getGroup(false);
               for (int k = 0; k < aa.length; k++)
                  pr("  GROUP: " + aa[k].toString(), level);
            }
         }
      }
View Full Code Here

   * @throws NullPointerException
   * @throws UnsupportedEncodingException
   */
  public static InternetAddress parseAddress(String sNamePlusEMail)
    throws AddressException,NullPointerException,UnsupportedEncodingException {
    InternetAddress oRetAdr = null;

    String sAddr = sNamePlusEMail.trim();

    int iLeftAng = sAddr.indexOf('<');
    int iRightAng= sAddr.indexOf('>');
    int iLeftPar = sAddr.indexOf('(');
    int iRightPar= sAddr.indexOf(')');
    int iLeftQuo = sAddr.indexOf('"');
    int iRightQuo;
    if (iLeftQuo>=0) iRightQuo = sAddr.indexOf('"',iLeftQuo+1); else iRightQuo = -1;

    if (iRightAng<iLeftAng) throw new AddressException("Misplaced right angle");
    if (iLeftAng<0 && iRightAng>=0) throw new AddressException("Missing left angle");
    if (iLeftAng>=0 && iRightAng<0) throw new AddressException("Missing right angle");
    if (iLeftPar<0 && iRightPar>=0) throw new AddressException("Missing left parenthesis");
    if (iLeftPar>=0 && iRightPar<0) throw new AddressException("Missing right parenthesis");
    if (iRightPar<iLeftPar) throw new AddressException("Misplaced right parenthesis");
    if (iLeftQuo>=0 && iRightQuo<0) throw new AddressException("Unclosed quote");

    if (iLeftAng>=0 && iRightAng>=0 && iLeftPar>=0 && iRightPar>=0) {
      // Address is (Name) <user@domain.com> or <user@domain.com> (Name)
      oRetAdr = new InternetAddress(sAddr.substring(iLeftAng+1,iRightAng),sAddr.substring(iLeftPar+1,iRightPar));
    } else if (iLeftAng>=0 && iRightAng>=0 && iLeftQuo>=0 && iRightQuo>=0) {
      // Address is "Name" <user@domain.com> or "Name" <user@domain.com>
      oRetAdr = new InternetAddress(sAddr.substring(iLeftAng+1,iRightAng),sAddr.substring(iLeftQuo+1,iRightQuo));
    } else if (iLeftAng>=0 && iRightAng>=0) {
      // Address is Name <user@domain.com> or <user@domain.com> Name
      if (0==iLeftAng)
        oRetAdr = new InternetAddress(sAddr.substring(1,iRightAng),sAddr.substring(iRightAng+1));
      else
        oRetAdr = new InternetAddress(sAddr.substring(iLeftAng+1,iRightAng),sAddr.substring(0,iLeftAng));
    } else {
      oRetAdr = new InternetAddress(sAddr);
    }
    return oRetAdr;
  }
View Full Code Here

   * Join mail addresses array on a single String
   * @param aRecipients Address[]
   * @return String Mail addresses delimited by semicolons
   */
  public static String joinAddressList (Address[] aRecipients) {
    InternetAddress oInetAdr;
    String sList = "";
    if (DebugFile.trace) {
      DebugFile.writeln("Begin RecipientsHelper.joinAddressList(Address[])");
      DebugFile.incIdent();
    }
    if (aRecipients!=null) {
      int cRecipients = aRecipients.length;
      if (cRecipients>0) {
        for (int a=0; a<cRecipients; a++) {
          oInetAdr = (InternetAddress) aRecipients[a];
          if (0!=a) sList += ";";
          sList += oInetAdr.getAddress();
        } // next
      } // fi (cRecipients>0)
    } // fi (aRecipients)
    if (DebugFile.trace) {
      DebugFile.writeln("End RecipientsHelper.joinAddressList() : " + sList);
View Full Code Here

                  iPos = aBccAddrs.length;
                  aBccSet = new InternetAddress[iLst+iPos];
                  System.arraycopy(aBccSet, 0, aBccAddrs, 0, iPos);
                }
                if (sPer==null) {
                  for (int l=0; l<iLst; l++) aBccSet[l+iPos] = new InternetAddress(aLst[l]);
                } else {
                  for (int l=0; l<iLst; l++) aBccSet[l+iPos] = new InternetAddress(aLst[l],sPer);
                } // fi (sPer)
                aBccAddrs = aBccSet;
                aRecipients[a] = null;
              } // fi (sLst!="")
            } // fi (aRecipients[a] LIKE list@%.list)
View Full Code Here

    try {
      aFrom = oMsg.getFrom();
    } catch (AddressException adre) {
      if (DebugFile.trace) DebugFile.writeln("From AddressException " + adre.getMessage());
    }
    InternetAddress oFrom;
    if (aFrom!=null) {
      if (aFrom.length>0)
        oFrom = (InternetAddress) aFrom[0];
      else
        oFrom = null;
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.