Auth.java
上传用户:liangcc
上传日期:2019-05-24
资源大小:4412k
文件大小:1k
- package com.softeem.webmail.auth;
- import java.util.Properties;
- import javax.mail.Session;
- import javax.mail.Transport;
- public class Auth {
- public boolean auth(String domain,String username,String password){
-
- Properties props = new Properties();
- //设置协议
- props.put("mail.transport.protocol", "smtp");
- //设置debug
- props.put("mail.debug", "true");
- //设置要登录验证
- props.put("mail.smtp.auth", "true");
- Session session = Session.getDefaultInstance(props,null);
- try {
- Transport trans = session.getTransport();
- trans.connect("smtp." + domain,username,password);
- if(trans.isConnected()){
- return true;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return false;
- }
- }