diff --git a/CHANGELOG.md b/CHANGELOG.md index c1af8055b..c9280d944 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### 新特性 * 【core 】 手机号工具类 座机正则表达式统一管理(pr#243@Gitee) +* 【extra 】 Mail增加setDebugOutput方法(issue#1335@Gitee) ### Bug修复 * 【core 】 修复ZipUtil.unzip从流解压关闭问题(issue#I2B0S1@Gitee) diff --git a/hutool-extra/src/main/java/cn/hutool/extra/mail/Mail.java b/hutool-extra/src/main/java/cn/hutool/extra/mail/Mail.java index 124fc2068..95137a7a9 100644 --- a/hutool-extra/src/main/java/cn/hutool/extra/mail/Mail.java +++ b/hutool-extra/src/main/java/cn/hutool/extra/mail/Mail.java @@ -25,6 +25,7 @@ import javax.mail.util.ByteArrayDataSource; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.io.PrintStream; import java.nio.charset.Charset; import java.util.Date; @@ -77,6 +78,11 @@ public class Mail { */ private boolean useGlobalSession = false; + /** + * debug输出位置,可以自定义debug日志 + */ + private PrintStream debugOutput; + /** * 创建邮件客户端 * @@ -345,6 +351,18 @@ public class Mail { this.useGlobalSession = isUseGlobalSession; return this; } + + /** + * 设置debug输出位置,可以自定义debug日志 + * + * @param debugOutput debug输出位置 + * @return this + * @since 5.5.6 + */ + public Mail setDebugOutput(PrintStream debugOutput) { + this.debugOutput = debugOutput; + return this; + } // --------------------------------------------------------------- Getters and Setters end /** @@ -453,8 +471,14 @@ public class Mail { authenticator = new UserPassAuthenticator(mailAccount.getUser(), mailAccount.getPass()); } - return isSingleton ? Session.getDefaultInstance(mailAccount.getSmtpProps(), authenticator) // + final Session session = isSingleton ? Session.getDefaultInstance(mailAccount.getSmtpProps(), authenticator) // : Session.getInstance(mailAccount.getSmtpProps(), authenticator); + + if(null != this.debugOutput){ + session.setDebugOut(debugOutput); + } + + return session; } // --------------------------------------------------------------- Private method end }