!12 新增一个nutzboot-starter-email

Merge pull request !12 from threefish/nutzboot-starter-email
This commit is contained in:
threefish 2018-08-10 15:42:27 +08:00 committed by Wendal
commit 93efadfd47
12 changed files with 161 additions and 0 deletions

View File

@ -213,6 +213,8 @@ public class MainLauncher {
- [x] starter-rabbitmq
- [ ] rocketmq
- [ ] activemq
- 邮件发送
- [x] starter-mail 基于commons-email by [threefish](https://github.com/threefish)
- 工作流
- [x] starter-[uflo](https://github.com/youseries/uflo) 中式工作流引擎
- [x] starter-[activiti](https://www.activiti.org/)

View File

@ -0,0 +1,25 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-demo-simple</artifactId>
<version>2.3-SNAPSHOT</version>
</parent>
<artifactId>nutzboot-demo-simple-email</artifactId>
<dependencies>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter-nutz-mvc</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
<dependency>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter-email</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,40 @@
package io.nutz.demo.simple;
import org.apache.commons.mail.ImageHtmlEmail;
import org.nutz.boot.NbApp;
import org.nutz.ioc.Ioc;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
@IocBean(create = "init")
public class MainLauncher {
private static final Log log = Logs.get();
@Inject("refer:$ioc")
protected Ioc ioc;
public static void main(String[] args) throws Exception {
new NbApp().setPrintProcDoc(true).run();
}
public void init() {
try {
//ImageHtmlEmail 请不要使用注入模式每次使用都需要去Ioc取一下
ImageHtmlEmail htmlEmail = ioc.get(ImageHtmlEmail.class);
htmlEmail.setSubject("NutzBootEmainStarter");
//请使用自己的邮箱
htmlEmail.addTo("自己的邮箱");
htmlEmail.setHtmlMsg("此邮件是Nutz Boot Email Starter发送给您的测试邮件");
log.debug("开始邮件发送");
htmlEmail.buildMimeMessage();
htmlEmail.sendMimeMessage();
log.debug("邮件发送完毕-请查收!注意有可能进入垃圾收件箱");
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
}

View File

@ -0,0 +1,10 @@
server.port=8080
server.host=0.0.0.0
email.HostName=smtp.exmail.qq.com
email.SmtpPort=465
email.UserName=
email.Password=
email.SSLOnConnect=true
email.From=
email.charset=UTF-8

View File

@ -0,0 +1,7 @@
log4j.rootLogger=debug,Console
log4j.logger.org.eclipse.jetty=info
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=[%-5p] %d{HH:mm:ss.SSS} %l - %m%n

View File

@ -48,6 +48,7 @@
<module>nutzboot-demo-simple-web3j</module>
<module>nutzboot-demo-simple-mqtt-client</module>
<module>nutzboot-demo-simple-elasticsearch</module>
<module>nutzboot-demo-simple-email</module>
</modules>
<dependencies>

View File

@ -0,0 +1,18 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.nutz</groupId>
<artifactId>nutzboot-starter</artifactId>
<version>2.3-SNAPSHOT</version>
</parent>
<artifactId>nutzboot-starter-email</artifactId>
<name>nutzboot-starter-email</name>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
<version>${commons.email.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,37 @@
package org.nutz.boot.starter.email;
import org.nutz.boot.annotation.PropDoc;
import org.nutz.boot.ioc.IocLoaderProvider;
import org.nutz.ioc.IocLoader;
import org.nutz.ioc.loader.json.JsonLoader;
public class EmailIocLoaderStarter implements IocLoaderProvider {
protected static final String PRE = "email.";
@PropDoc(group = "email", value = "email的ip或域名地址", need = true)
public static final String PROP_HOSTNAME = PRE + "HostName";
@PropDoc(group = "email", value = "email的SmtpPort端口", need = true)
public static final String PROP_SMTPPORT = PRE + "SmtpPort";
@PropDoc(group = "email", value = "email的用户名", need = true)
public static final String PROP_USERNAME = PRE + "UserName";
@PropDoc(group = "email", value = "email的密码", need = true)
public static final String PROP_PASSWORD = PRE + "Password";
@PropDoc(group = "email", value = "email开启SSL连接", defaultValue = "true", type = "boolean")
public static final String PROP_SSLONCONNECT = PRE + "SSLOnConnect";
@PropDoc(group = "email", value = "email的写信人", need = true)
public static final String PROP_FROM = PRE + "From";
@PropDoc(group = "email", value = "email的编码", defaultValue = "UTF-8")
public static final String PROP_CHARSET = PRE + "charset";
@Override
public IocLoader getIocLoader() {
return new JsonLoader("org/nutz/boot/starter/email/email.js");
}
}

View File

@ -0,0 +1 @@
org.nutz.boot.starter.email.EmailIocLoaderStarter

View File

@ -0,0 +1,18 @@
var ioc = {
emailAuthenticator: {
type: "org.apache.commons.mail.DefaultAuthenticator",
args: [{java: "$conf.get('email.UserName')"}, {java: "$conf.get('email.Password')"}]
},
imageHtmlEmail: {
type: "org.apache.commons.mail.ImageHtmlEmail",
singleton: false,
fields: {
hostName: {java: "$conf.get('email.HostName')"},
smtpPort: {java: "$conf.get('email.SmtpPort')"},
authenticator: {refer: "emailAuthenticator"},
SSLOnConnect: {java: "$conf.get('email.SSLOnConnect')"},
from: {java: "$conf.get('email.From')"},
charset: {java: "$conf.get('email.charset')"}
}
}
};

View File

@ -63,6 +63,7 @@
<module>nutzboot-servlet3</module>
<module>nutzboot-spring4</module>
<module>nutzboot-starter-elasticsearch</module>
<module>nutzboot-starter-email</module>
</modules>
<dependencies>
<dependency>

View File

@ -37,6 +37,7 @@
<thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
<quartz.version>2.3.0</quartz.version>
<elasticsearch.version>6.3.0</elasticsearch.version>
<commons.email.version>1.4</commons.email.version>
</properties>
<description>NutzBoot, micoservice base on Nutz</description>