package com.sidiw.util.jmail; import java.util.Properties; import javax.mail.Session; public class ConnectMail { private Session session; private Transport transport; private Store store; private Properties properties; /** 返回过的实例在验证通过后使用 */ public Session getSession() { public Store getStore() { public Transport getTransport() { public boolean connectSmtp(String smtpHost, String uid, String pwd) { properties.put("mail.smtp.auth", "true"); transport = session.getTransport("smtp"); public boolean connectPop3(String popHost, String uid, String pwd) { try { session = Session.getDefaultInstance(properties, null); return true; } catch (Exception e) {
import javax.mail.Store;
import javax.mail.Transport;
return session;
}
return store;
}
return transport;
}
try {
properties = new java.util.Properties();
properties.put("mail.smtp.host", smtpHost);
Auth auth = new Auth(uid, pwd);
session = Session.getInstance(properties, auth);
transport.connect();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
properties = new java.util.Properties();
store = session.getStore("pop3");
store.connect(popHost, uid, pwd);
e.printStackTrace();
return false;
}
}
}