WEB开发网
开发学院WEB开发Jsp Jmail收发邮件时的连接验证类 阅读

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

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;


Tags:Jmail 收发 邮件

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接