提交 588933a7 编写于 作者: L Looly

add customProperty

上级 7e0dda4b
......@@ -3,7 +3,7 @@
-------------------------------------------------------------------------------------------------------------
# 5.6.4 (2021-04-22)
# 5.6.4 (2021-04-23)
### 🐣新特性
* 【core 】 DatePattern补充DateTimeFormatter(pr#308@Gitee)
......@@ -11,6 +11,7 @@
* 【core 】 BeanUtil增加edit方法(issue#I3J6BG@Gitee)
* 【db 】 Column中加入columnDef字段默认值(issue#I3J6BG@Gitee)
* 【core 】 BeanUtil增加copyToList方法(issue#1526@Github)
* 【extra 】 MailAccount增加customProperty可以用户自定义属性(pr#317@Gitee)
### 🐞Bug修复
* 【db 】 修复SQL分页时未使用别名导致的错误,同时count时取消order by子句(issue#I3IJ8X@Gitee)
......
......@@ -39,9 +39,6 @@ public class MailAccount implements Serializable {
public static final String[] MAIL_SETTING_PATHS = new String[]{"config/mail.setting", "config/mailAccount.setting", "mail.setting"};
// 允许使用自定义属性
private final Map<String, Object> customProperty = new HashMap<>();
/**
* SMTP服务器域名
*/
......@@ -116,6 +113,11 @@ public class MailAccount implements Serializable {
*/
private long connectionTimeout;
/**
* 自定义的其他属性,此自定义属性会覆盖默认属性
*/
private final Map<String, Object> customProperty = new HashMap<>();
// -------------------------------------------------------------- Constructor start
/**
......@@ -477,6 +479,7 @@ public class MailAccount implements Serializable {
* 获取自定义属性列表
*
* @return 自定义参数列表
* @since 5.6.4
*/
public Map<String, Object> getCustomProperty() {
return customProperty;
......@@ -485,12 +488,13 @@ public class MailAccount implements Serializable {
/**
* 设置自定义属性,如mail.smtp.ssl.socketFactory
*
* @param key 属性名
* @param value 属性值
* @param key 属性名,空白被忽略
* @param value 属性值, null被忽略
* @return this
* @since 5.6.4
*/
public MailAccount setCustomProperty(String key, Object value) {
if (ObjectUtil.isNotNull(key) && ObjectUtil.isNotNull(value)) {
if (StrUtil.isNotBlank(key) && ObjectUtil.isNotNull(value)) {
this.customProperty.put(key, value);
}
return this;
......@@ -542,9 +546,7 @@ public class MailAccount implements Serializable {
}
// 补充自定义属性,允许自定属性覆盖已经设置的值
for (String key : customProperty.keySet()) {
p.put(key, customProperty.get(key));
}
p.putAll(this.customProperty);
return p;
}
......
......@@ -2,6 +2,7 @@ package cn.hutool.extra.mail;
import com.sun.mail.util.MailSSLSocketFactory;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import java.security.GeneralSecurityException;
......@@ -22,14 +23,15 @@ public class MailAccountTest {
Assert.assertTrue(account.isSslEnable());
}
/*
测试案例:使用QQ邮箱、AOL邮箱,如果不改SocketFactory实例,会报错(unable to find valid certification path to requested target),
hutool mail中仅提供了'mail.smtp.socketFactory.class'属性,但是没提供'mail.smtp.ssl.socketFactory'属性
参见 com.sun.mail.util.SocketFetcher.getSocket(java.lang.String, int, java.util.Properties, java.lang.String, boolean)
已经测试通过
/**
* 测试案例:使用QQ邮箱、AOL邮箱,如果不改SocketFactory实例,会报错(unable to find valid certification path to requested target),
* hutool mail中仅提供了'mail.smtp.socketFactory.class'属性,但是没提供'mail.smtp.ssl.socketFactory'属性
* 参见 com.sun.mail.util.SocketFetcher.getSocket(java.lang.String, int, java.util.Properties, java.lang.String, boolean)
* <p>
* 已经测试通过
*/
@Test
@Ignore
public void customPropertyTest() throws GeneralSecurityException {
MailAccount mailAccount = new MailAccount();
mailAccount.setFrom("xxx@xxx.com");
......
package cn.hutool.extra.mail;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import cn.hutool.core.io.FileUtil;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import cn.hutool.core.io.FileUtil;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
/**
* 邮件发送测试
......@@ -17,20 +16,20 @@ import cn.hutool.core.io.FileUtil;
*
*/
public class MailTest {
@Test
@Ignore
public void sendWithFileTest() {
MailUtil.send("hutool@foxmail.com", "测试", "<h1>邮件来自Hutool测试</h1>", true, FileUtil.file("d:/测试附件文本.txt"));
}
@Test
@Ignore
public void sendWithLongNameFileTest() {
//附件名长度大于60时的测试
MailUtil.send("hutool@foxmail.com", "测试", "<h1>邮件来自Hutool测试</h1>", true, FileUtil.file("d:/6-LongLong一阶段平台建设周报2018.3.12-3.16.xlsx"));
}
@Test
@Ignore
public void sendWithImageTest() {
......@@ -38,13 +37,13 @@ public class MailTest {
map.put("testImage", FileUtil.getInputStream("f:/test/me.png"));
MailUtil.sendHtml("hutool@foxmail.com", "测试", "<h1>邮件来自Hutool测试</h1><img src=\"cid:testImage\" />", map);
}
@Test
@Ignore
public void sendHtmlTest() {
MailUtil.send("hutool@foxmail.com", "测试", "<h1>邮件来自Hutool测试</h1>", true);
}
@Test
@Ignore
public void sendByAccountTest() {
......@@ -55,9 +54,9 @@ public class MailTest {
account.setFrom("hutool@yeah.net");
account.setUser("hutool");
account.setPass("q1w2e3");
MailUtil.send(account, "914104645@qq.com", "测试", "<h1>邮件来自Hutool测试</h1>", true);
MailUtil.send(account, "hutool@foxmail.com", "测试", "<h1>邮件来自Hutool测试</h1>", true);
}
@Test
public void mailAccountTest() {
MailAccount account = new MailAccount();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册