add method for #1335

This commit is contained in:
Looly 2020-12-29 19:33:15 +08:00
parent b8e5cc006e
commit 648ba17107
2 changed files with 26 additions and 1 deletions

View File

@ -7,6 +7,7 @@
### 新特性 ### 新特性
* 【core 】 手机号工具类 座机正则表达式统一管理pr#243@Gitee * 【core 】 手机号工具类 座机正则表达式统一管理pr#243@Gitee
* 【extra 】 Mail增加setDebugOutput方法issue#1335@Gitee
### Bug修复 ### Bug修复
* 【core 】 修复ZipUtil.unzip从流解压关闭问题issue#I2B0S1@Gitee * 【core 】 修复ZipUtil.unzip从流解压关闭问题issue#I2B0S1@Gitee

View File

@ -25,6 +25,7 @@ import javax.mail.util.ByteArrayDataSource;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.PrintStream;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.Date; import java.util.Date;
@ -77,6 +78,11 @@ public class Mail {
*/ */
private boolean useGlobalSession = false; private boolean useGlobalSession = false;
/**
* debug输出位置可以自定义debug日志
*/
private PrintStream debugOutput;
/** /**
* 创建邮件客户端 * 创建邮件客户端
* *
@ -345,6 +351,18 @@ public class Mail {
this.useGlobalSession = isUseGlobalSession; this.useGlobalSession = isUseGlobalSession;
return this; 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 // --------------------------------------------------------------- Getters and Setters end
/** /**
@ -453,8 +471,14 @@ public class Mail {
authenticator = new UserPassAuthenticator(mailAccount.getUser(), mailAccount.getPass()); 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); : Session.getInstance(mailAccount.getSmtpProps(), authenticator);
if(null != this.debugOutput){
session.setDebugOut(debugOutput);
}
return session;
} }
// --------------------------------------------------------------- Private method end // --------------------------------------------------------------- Private method end
} }