Jmail收发邮件时的连接验证类
2008-01-05 18:33:30 来源:WEB开发网package com.sidiw.util.jmail;
import java.util.PRoperties;
import javax.mail.session;
import javax.mail.Store;
import javax.mail.Transport;
public class ConnectMail {
private Session session;
private Transport transport;
private Store store;
private Properties properties;
/** 返回过的实例在验证通过后使用 */
public Session getSession() {
return session;
}
public Store getStore() {
return store;
}
public Transport getTransport() {
return transport;
}
public boolean connectSmtp(String smtpHost, String uid, String pwd) {
try {
properties = new java.util.Properties();
properties.put("mail.smtp.host", smtpHost);
properties.put("mail.smtp.auth", "true");
Auth auth = new Auth(uid, pwd);
session = Session.getInstance(properties, auth);
transport = session.getTransport("smtp");
transport.connect();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public boolean connectPop3(String popHost, String uid, String pwd) {
try {
properties = new java.util.Properties();
session = Session.getDefaultInstance(properties, null);
store = session.getStore("pop3");
store.connect(popHost, uid, pwd);
return true;
更多精彩
赞助商链接