Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zhangjian1949
apollo
提交
f8683a24
apollo
项目概览
zhangjian1949
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
f8683a24
编写于
12月 11, 2020
作者:
N
nisiyong
提交者:
Jason Song
12月 12, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: support default email feature via portal config
上级
e35ce8c0
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
137 addition
and
14 deletion
+137
-14
apollo-portal/pom.xml
apollo-portal/pom.xml
+4
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java
...ramework/apollo/portal/component/config/PortalConfig.java
+21
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/bo/Email.java
...va/com/ctrip/framework/apollo/portal/entity/bo/Email.java
+4
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultEmailService.java
...rk/apollo/portal/spi/defaultimpl/DefaultEmailService.java
+92
-3
pom.xml
pom.xml
+16
-10
未找到文件。
apollo-portal/pom.xml
浏览文件 @
f8683a24
...
...
@@ -50,6 +50,10 @@
<groupId>
javax.activation
</groupId>
<artifactId>
activation
</artifactId>
</dependency>
<dependency>
<groupId>
com.sun.mail
</groupId>
<artifactId>
javax.mail
</artifactId>
</dependency>
<!-- end of JDK 1.8+ -->
<!-- JDK 11+ -->
<dependency>
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java
浏览文件 @
f8683a24
...
...
@@ -187,8 +187,28 @@ public class PortalConfig extends RefreshableConfig {
return
getValue
(
"consumer.token.salt"
,
"apollo-portal"
);
}
public
boolean
isEmailEnabled
()
{
return
getBooleanProperty
(
"email.enabled"
,
false
);
}
public
String
emailConfigHost
()
{
return
getValue
(
"email.config.host"
,
""
);
}
public
String
emailConfigUser
()
{
return
getValue
(
"email.config.user"
,
""
);
}
public
String
emailConfigPassword
()
{
return
getValue
(
"email.config.password"
,
""
);
}
public
String
emailSender
()
{
return
getValue
(
"email.sender"
);
String
value
=
getValue
(
"email.sender"
,
""
);
if
(
Strings
.
isNullOrEmpty
(
value
))
{
value
=
emailConfigUser
();
}
return
value
;
}
public
String
emailTemplateFramework
()
{
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/bo/Email.java
浏览文件 @
f8683a24
...
...
@@ -21,6 +21,10 @@ public class Email {
return
recipients
;
}
public
String
getRecipientsString
()
{
return
String
.
join
(
","
,
recipients
);
}
public
void
setRecipients
(
List
<
String
>
recipients
)
{
this
.
recipients
=
recipients
;
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/defaultimpl/DefaultEmailService.java
浏览文件 @
f8683a24
package
com.ctrip.framework.apollo.portal.spi.defaultimpl
;
import
com.ctrip.framework.apollo.portal.component.config.PortalConfig
;
import
com.ctrip.framework.apollo.portal.entity.bo.Email
;
import
com.ctrip.framework.apollo.portal.spi.EmailService
;
import
com.ctrip.framework.apollo.tracer.Tracer
;
import
com.sun.mail.smtp.SMTPTransport
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.util.Properties
;
import
javax.activation.DataHandler
;
import
javax.activation.DataSource
;
import
javax.annotation.Resource
;
import
javax.mail.Message
;
import
javax.mail.Session
;
import
javax.mail.internet.InternetAddress
;
import
javax.mail.internet.MimeMessage
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
public
class
DefaultEmailService
implements
EmailService
{
public
class
DefaultEmailService
implements
EmailService
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
DefaultEmailService
.
class
);
@Resource
private
PortalConfig
portalConfig
;
@Override
public
void
send
(
Email
email
){
//do nothing
public
void
send
(
Email
email
)
{
if
(!
portalConfig
.
isEmailEnabled
())
{
return
;
}
SMTPTransport
t
=
null
;
try
{
Properties
prop
=
System
.
getProperties
();
Session
session
=
Session
.
getInstance
(
prop
,
null
);
Message
msg
=
new
MimeMessage
(
session
);
msg
.
setFrom
(
new
InternetAddress
(
email
.
getSenderEmailAddress
()));
msg
.
setRecipients
(
Message
.
RecipientType
.
TO
,
InternetAddress
.
parse
(
email
.
getRecipientsString
(),
false
));
msg
.
setSubject
(
email
.
getSubject
());
msg
.
setDataHandler
(
new
DataHandler
(
new
HTMLDataSource
(
email
.
getBody
())));
String
host
=
portalConfig
.
emailConfigHost
();
String
user
=
portalConfig
.
emailConfigUser
();
String
password
=
portalConfig
.
emailConfigPassword
();
t
=
(
SMTPTransport
)
session
.
getTransport
(
"smtp"
);
t
.
connect
(
host
,
user
,
password
);
msg
.
saveChanges
();
t
.
sendMessage
(
msg
,
msg
.
getAllRecipients
());
logger
.
debug
(
"email response: {}"
,
t
.
getLastServerResponse
());
}
catch
(
Exception
e
)
{
logger
.
error
(
"send email failed."
,
e
);
Tracer
.
logError
(
"send email failed."
,
e
);
}
finally
{
if
(
t
!=
null
)
{
try
{
t
.
close
();
}
catch
(
Exception
e
)
{
// nothing
}
}
}
}
static
class
HTMLDataSource
implements
DataSource
{
private
String
html
;
HTMLDataSource
(
String
htmlString
)
{
html
=
htmlString
;
}
@Override
public
InputStream
getInputStream
()
throws
IOException
{
if
(
html
==
null
)
{
throw
new
IOException
(
"html message is null!"
);
}
return
new
ByteArrayInputStream
(
html
.
getBytes
());
}
@Override
public
OutputStream
getOutputStream
()
throws
IOException
{
throw
new
IOException
(
"This DataHandler cannot write HTML"
);
}
@Override
public
String
getContentType
()
{
return
"text/html"
;
}
@Override
public
String
getName
()
{
return
"HTMLDataSource"
;
}
}
}
pom.xml
浏览文件 @
f8683a24
...
...
@@ -79,9 +79,10 @@
<platform-bom.version>
Cairo-SR4
</platform-bom.version>
<spring-boot.version>
2.0.5.RELEASE
</spring-boot.version>
<spring-cloud.version>
Finchley.SR1
</spring-cloud.version>
<jaxb.version>
2.3.0
</jaxb.version>
<javax.activation.version>
1.1.1
</javax.activation.version>
<javassist.version>
3.23.1-GA
</javassist.version>
<jaxb.version>
2.3.0
</jaxb.version>
<javax.activation.version>
1.1.1
</javax.activation.version>
<javax.mail.version>
1.6.2
</javax.mail.version>
<javassist.version>
3.23.1-GA
</javassist.version>
<!-- Plugins Version -->
<maven-compiler-plugin.version>
3.6.0
</maven-compiler-plugin.version>
<maven-surefire-plugin.version>
2.19.1
</maven-surefire-plugin.version>
...
...
@@ -349,13 +350,18 @@
<artifactId>
activation
</artifactId>
<version>
${javax.activation.version}
</version>
</dependency>
<!-- JDK 11+ -->
<dependency>
<groupId>
org.javassist
</groupId>
<artifactId>
javassist
</artifactId>
<version>
${javassist.version}
</version>
</dependency>
<!-- end of JDK 11+ -->
<dependency>
<groupId>
com.sun.mail
</groupId>
<artifactId>
javax.mail
</artifactId>
<version>
${javax.mail.version}
</version>
</dependency>
<!-- JDK 11+ -->
<dependency>
<groupId>
org.javassist
</groupId>
<artifactId>
javassist
</artifactId>
<version>
${javassist.version}
</version>
</dependency>
<!-- end of JDK 11+ -->
</dependencies>
</dependencyManagement>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录