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) {