
com.moon.core.mail.EmailAccount Maven / Gradle / Ivy
package com.moon.core.mail;
import com.moon.core.lang.MoonUtil;
import com.moon.core.lang.ThrowUtil;
import com.sun.mail.util.MailSSLSocketFactory;
import javax.mail.*;
import java.io.Serializable;
import java.security.GeneralSecurityException;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
/**
* @author moonsky
* @see EmailUtil
*/
public class EmailAccount implements Cloneable, Serializable {
private static final String NULL = null;
private static final boolean FALSE = false;
private String username;
private String password;
private boolean SSLEncrypt;
private Properties properties;
private ExecutorService service;
/******************** constructor ******************************************************/
public EmailAccount(String host) {
this(host, NULL, NULL);
}
public EmailAccount(String host, boolean sslEncrypt) {
this(host, NULL, NULL, sslEncrypt);
}
public EmailAccount(String host, String username, String password) {
this(host, username, password, FALSE);
}
public EmailAccount(String host, String username, String password, boolean sslEncrypt) {
this.setHost(host);
this.setSSLEncrypt(sslEncrypt);
this.login(username, password);
}
public EmailAccount(String host, String username, String password, Integer timeout, boolean sslEncrypt) {
this.setHost(host);
this.setTimeout(timeout);
this.setSSLEncrypt(sslEncrypt);
this.login(username, password);
}
/******************** getter and setter ******************************************************/
public String getHost() {
return getProperty(MAIL_HOST_KEY);
}
public EmailAccount setHost(String host) {
return this.setProperty(MAIL_HOST_KEY, host);
}
public EmailAccount login(String username, String password) {
this.setUsername(username);
this.setPassword(password);
return this;
}
public String getUsername() {
return username;
}
public EmailAccount setUsername(String username) {
this.username = username;
return this;
}
public String getPassword() {
return password;
}
public EmailAccount setPassword(String password) {
this.password = password;
return this;
}
public boolean isSSLEncrypt() {
return SSLEncrypt;
}
public EmailAccount setSSLEncrypt(boolean SSLEncrypt) {
this.SSLEncrypt = SSLEncrypt;
return this;
}
public Integer getTimeout() {
return (Integer) getProperties().get(MAIL_TIMEOUT_KEY);
}
public EmailAccount setTimeout(Integer timeout) {
if (timeout != null) {
return this.setProperty(MAIL_TIMEOUT_KEY, timeout);
}
return this;
}
public Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy