add customProperty

This commit is contained in:
Looly
2021-04-23 09:52:52 +08:00
parent 7e0dda4b41
commit 588933a733
4 changed files with 33 additions and 29 deletions

View File

@@ -3,7 +3,7 @@
-------------------------------------------------------------------------------------------------------------
# 5.6.4 (2021-04-22)
# 5.6.4 (2021-04-23)
### 🐣新特性
* 【core 】 DatePattern补充DateTimeFormatterpr#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

View File

@@ -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;
}

View File

@@ -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");

View File

@@ -1,16 +1,15 @@
package cn.hutool.extra.mail;
import cn.hutool.core.io.FileUtil;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import cn.hutool.core.io.FileUtil;
/**
* 邮件发送测试
* @author looly
@@ -55,7 +54,7 @@ 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