Package javax.mail.internet

Examples of javax.mail.internet.InternetAddress


        if(mailc > 1)
          timeToSleep = 0;
        if(mails.size()>0){
          for(;i<mails.size();i++){
            MimeMessage mail = (MimeMessage)mails.get(i);
            mail.setFrom(new InternetAddress(sender,"DLOG4J Messenger"));
            if(userDNSQuery){
              //�ؿ�ר��
              String email = mail.getRecipients(RecipientType.TO)[0].toString();
              String domain_name = parseDomain(email);
              //TODO: ʵ�������Ļ���,�ӿ�����ٶ�
              Lookup lookup = new Lookup(domain_name, Type.MX);
                  lookup.run();
              if (lookup.getResult() != Lookup.SUCCESSFUL){
                log("ERROR: " + lookup.getErrorString() + " when lookup MX record of " + email);
                continue;
              }
              Record[] answers = lookup.getAnswers();
              for(int ai=0;ai<answers.length;ai++){
                Transport transport = null;
                    log("Using " + answers[i].getAdditionalName()+" to send mail to " + email);
                    String mx_host = answers[i].getAdditionalName().toString();
                    mailSession.getProperties().put("mail.smtp.host", mx_host);
                    InternetAddress smtp_host = new InternetAddress(mx_host);
                    try {
                        transport = mailSession.getTransport(smtp_host);
                        try {
                            transport.connect();
                            log("INFO: connected to "+mx_host);
                        } catch (MessagingException me) {
                            // Any error on connect should cause the mailet to attempt
                            // to connect to the next SMTP server associated with this
                            // MX record.  Just log the exception.  We'll worry about
                            // failing the message at the end of the loop.
                            me.printStackTrace();
                            log("ERROR: Connecto to " + mx_host + " failed." , me);
                            continue;
                        }
                        InternetAddress mailToAddress = new InternetAddress(email);           
                        transport.sendMessage(mail, new InternetAddress[]{mailToAddress});
                        log("INFO: mail sent to " + email);
                        break;
                    } finally {
                        if (transport != null) {
View Full Code Here


          Multipart multipart = new MimeMultipart("related");
      MimeBodyPart messageBodyPart = new MimeBodyPart();
          messageBodyPart.setText("Welcome to JavaMail.");
          multipart.addBodyPart(messageBodyPart);
          mailMessage.setContent(multipart);
          mailMessage.setFrom(new InternetAddress("javayou@gmail.com","Winter Lau"));
         
          String mail_postfix = mailaddr.substring(mailaddr.indexOf('@')+1);
          //System.out.println("mail postfix is " + mail_postfix);
          Lookup lookup = new Lookup(mail_postfix, Type.MX);
          lookup.run();
      if (lookup.getResult() != Lookup.SUCCESSFUL){
        System.out.println(" " + lookup.getErrorString());
        return;
      }
      Record[] answers = lookup.getAnswers();
      for(int i=0;i<answers.length;i++){
            Transport transport = null;
            //System.out.println("Using " + answers[i].getAdditionalName()+" to send...");
            ssn.getProperties().put("mail.smtp.host", answers[i].getAdditionalName().toString());
            InternetAddress smtp_host = new InternetAddress(answers[i].getAdditionalName().toString());
            try {
                transport = ssn.getTransport(smtp_host);
                  transport.connect();
                  System.out.println("connect to "+smtp_host+" ok.");
                InternetAddress mailToAddress = new InternetAddress(mailaddr);           
                transport.sendMessage(mailMessage, new InternetAddress[]{mailToAddress});
                System.out.println("mail sent to " + mailaddr + " via " + smtp_host);
                break;
              } catch (MessagingException me) {
                  // Any error on connect should cause the mailet to attempt
View Full Code Here

                throw new AddressException();
            }

            Address[] replyTo = new Address[1];

            replyTo[0] = new InternetAddress(addstr);
            message.setReplyTo(replyTo);
        } catch (Exception mx) {
            System.err.println("Error in MailObject.setReplyTo(): "+mx);
            setStatus(REPLYTO);
        }
View Full Code Here

            }

            Address address = null;

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

            message.setFrom(address);
        } catch (Exception mx) {
            System.err.println("Error in MailObject.setFrom(): "+mx);
View Full Code Here

        }

        Address address = null;

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

        message.addRecipient(type, address);
    }
View Full Code Here

  private String appendAddresses(ArrayList addressList)
  {
    StringBuffer addresses = new StringBuffer();
    Iterator iter = addressList.iterator();
    while (iter.hasNext()) {
      InternetAddress address = (InternetAddress)iter.next();
      addresses.append(address.toString());
      if (iter.hasNext()) {
        addresses.append(", ");
      }
    }
    return(addresses.toString());
View Full Code Here

  private String appendCcAddresses(ArrayList addressList)
  {
    StringBuffer addresses = new StringBuffer();
    Iterator iter = addressList.iterator();
    while (iter.hasNext()) {
      InternetAddress address = (InternetAddress) iter.next();
      addresses.append(address.toString());
      if (iter.hasNext()) {
        addresses.append(", ");
      }
    }
    return (addresses.toString());
View Full Code Here

            String address = "";
            try {
              if (mergeType.equals("EMAIL")) {
                address = printTemplate.getEmail();
                name = printTemplate.getFirstName() + " " + printTemplate.getLastName();
                InternetAddress internetAddress = new InternetAddress(address, name);
                emailList.add(internetAddress.toString());
              }
              // templateList is sample template with update information of the
              // Individual.
              templateList.add(tempData);
            } catch (UnsupportedEncodingException e) {
View Full Code Here

  public static boolean isEmailAddressValid(String address)
  {
    boolean result = true;
    try {
      new InternetAddress(address);
    } catch (AddressException ae) {
      result = false;
    } catch (NullPointerException npe) {
      result = false;
    }
View Full Code Here

        while (iter.hasNext()) {
          Number accountID = (Number)iter.next();
          MailAccountVO accountVO = remote.getMailAccountVO(accountID.intValue());
          HashMap accountDetails = new HashMap();
          accountDetails.put("accountID", new Integer(accountID.intValue()));
          accountDetails.put("accountName", new InternetAddress(accountVO.getEmailAddress(), mailUtils.stripInvalidCharsFromName(accountVO.getIndividualName())));
          accountList.add(accountDetails);
        }
      }
      emailForm.set("accountList", accountList);
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.