提交 2755e7c6 编写于 作者: Z zhourui

新增加邮件

上级 76d6c103
......@@ -320,6 +320,14 @@
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
</dependency>
</dependencies>
<build>
......@@ -797,6 +805,16 @@
<artifactId>jedis</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>o2oa</groupId>
<artifactId>x_base_core_project</artifactId>
......
......@@ -77,6 +77,7 @@ public class Config {
public static final String PATH_CONFIG_PORTAL = "config/portal.json";
public static final String PATH_CONFIG_CACHE = "config/cache.json";
public static final String PATH_CONFIG_COMPONENTS = "config/components.json";
public static final String PATH_CONFIG_EMAIL = "config/email.json";
public static final String DIR_COMMONS = "commons";
public static final String DIR_COMMONS_TESS4J_TESSDATA = "commons/tess4j/tessdata";
......@@ -1276,6 +1277,19 @@ public class Config {
return instance().cache;
}
public Email email;
public static synchronized Email email() throws Exception {
if (null == instance().email) {
Email obj = BaseTools.readConfigObject(PATH_CONFIG_EMAIL, Email.class);
if (null == obj) {
obj = Email.defaultInstance();
}
instance().email = obj;
}
return instance().email;
}
private Components components = null;
public static Components components() throws Exception {
......
package com.x.base.core.project.config;
import org.apache.commons.lang3.BooleanUtils;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.tools.NumberTools;
public class Email extends ConfigObject {
public static final Boolean DEFAULT_ENABLE = false;
public static final String DEFAULT_HOST = "";
public static final Integer DEFAULT_PORT = 25;
public static final Integer DEFAULT_SSLPORT = 465;
public static final Boolean DEFAULT_SSLENABLE = false;
public static final String DEFAULT_FROM = "";
public static final String DEFAULT_USER = "";
public static final String DEFAULT_PASS = "";
public static Email defaultInstance() {
return new Email();
}
public Email() {
this.enable = DEFAULT_ENABLE;
this.host = DEFAULT_HOST;
this.port = DEFAULT_PORT;
this.sslEnable = DEFAULT_SSLENABLE;
this.from = DEFAULT_FROM;
this.user = DEFAULT_USER;
this.pass = DEFAULT_PASS;
}
@FieldDescribe("是否启用")
private Boolean enable;
@FieldDescribe("SMTP主机地址")
private String host;
@FieldDescribe("SMTP发送端口")
private Integer port;
@FieldDescribe("是否启用ssl")
private Boolean sslEnable;
@FieldDescribe("发送人")
private String from;
@FieldDescribe("用户名")
private String user;
@FieldDescribe("密码")
private String pass;
public Boolean getEnable() {
return BooleanUtils.isTrue(this.enable);
}
public String getHost() {
return host;
}
public Integer getPort() {
if (NumberTools.nullOrLessThan(this.port, 1)) {
if (BooleanUtils.isTrue(this.sslEnable)) {
return DEFAULT_SSLPORT;
} else {
return DEFAULT_PORT;
}
} else {
return this.port;
}
}
public Boolean getSslEnable() {
return BooleanUtils.isTrue(this.sslEnable);
}
public String getFrom() {
return from;
}
public String getUser() {
return user;
}
public String getPass() {
return pass;
}
}
package com.x.base.core.project.message;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.HtmlEmail;
import org.apache.commons.mail.ImageHtmlEmail;
import org.apache.commons.mail.MultiPartEmail;
import org.apache.commons.mail.SimpleEmail;
import com.x.base.core.project.config.Config;
public class EmailFactory {
private EmailFactory() {
// nothing
}
public static HtmlEmail htmlEmail() throws Exception {
if (BooleanUtils.isNotTrue(Config.email().getEnable())) {
throw new ExceptionEmailNotEnable();
}
HtmlEmail email = new HtmlEmail();
init(email);
return email;
}
public static ImageHtmlEmail imageHtmlEmail() throws Exception {
if (BooleanUtils.isNotTrue(Config.email().getEnable())) {
throw new ExceptionEmailNotEnable();
}
ImageHtmlEmail email = new ImageHtmlEmail();
init(email);
return email;
}
public static MultiPartEmail multiPartEmail() throws Exception {
if (BooleanUtils.isNotTrue(Config.email().getEnable())) {
throw new ExceptionEmailNotEnable();
}
MultiPartEmail email = new MultiPartEmail();
init(email);
return email;
}
public static SimpleEmail simpleEmail() throws Exception {
if (BooleanUtils.isNotTrue(Config.email().getEnable())) {
throw new ExceptionEmailNotEnable();
}
SimpleEmail email = new SimpleEmail();
init(email);
return email;
}
private static void init(Email email) throws Exception {
email.setHostName(Config.email().getHost());
email.setSmtpPort(Config.email().getPort());
email.setAuthenticator(new DefaultAuthenticator(Config.email().getUser(), Config.email().getPass()));
email.setSSLOnConnect(Config.email().getSslEnable());
email.setFrom(Config.email().getFrom());
}
}
package com.x.base.core.project.message;
import com.x.base.core.project.exception.PromptException;
class ExceptionEmailNotEnable extends PromptException {
private static final long serialVersionUID = 6226334698900029283L;
ExceptionEmailNotEnable() {
super("email disabled.");
}
}
\ No newline at end of file
......@@ -16,11 +16,11 @@ public class NumberTools {
return NumberUtils.compare(x, y) == 0;
}
public static Boolean greaterThan(Integer x, Integer y) {
public static Boolean greaterThan(Number x, Number y) {
if (null == x || null == y) {
return false;
}
return x > y;
return x.doubleValue() > y.doubleValue();
}
public static Integer valueEuqalsThan(Integer x, Integer y, Integer euqalsValue, Integer notEuqalsValue) {
......@@ -74,11 +74,11 @@ public class NumberTools {
return null;
}
public static boolean nullOrLessThan(Integer value, Number number) {
public static boolean nullOrLessThan(Number value, Number number) {
if (value == null) {
return true;
}
return value < number.intValue();
return value.doubleValue() < number.doubleValue();
}
}
......@@ -162,7 +162,7 @@ public class ApplicationServerTools extends JettySeverTools {
webApp.setContextPath("/" + name);
webApp.setResourceBase(dir.getAbsolutePath());
webApp.setDescriptor(dir + "/WEB-INF/web.xml");
webApp.setExtraClasspath(calculateExtraClassPath(cls, dir.toPath().resolve("WEB-INF/lib")));
webApp.setExtraClasspath(calculateExtraClassPath(cls));
webApp.getInitParams().put("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false");
webApp.getInitParams().put("org.eclipse.jetty.jsp.precompiled", "true");
webApp.getInitParams().put("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册