Jmail收发邮件时的连接验证类

2008-02-23 09:31:21来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

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;

} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}

上一篇: 利用Jmail发带附件的邮件
下一篇: Shark中的ToolAgent用法-RuntimeApplicationToolAgent

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Spirng下的log4j设置 [引用]

下一篇:Is it a problem on Regex or Static