diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java index 06376708..b406a21e 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/email/EmailServiceManager.java @@ -556,7 +556,24 @@ public class EmailServiceManager { final String rootPath = spectrumPathProperties.getRootPath(); final String emlPath = spectrumPathProperties.getEmlPath(); emlFile = new File(rootPath+emlPath+File.separator+fileName); - message.writeTo(new FileOutputStream(emlFile)); +// message.writeTo(new FileOutputStream(emlFile)); + + int bufferSize = 1024 * 1024; // 1M + InputStream inputStream = message.getInputStream(); + BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream, bufferSize); + // 或者使用 BufferedOutputStream + OutputStream outputStream = new FileOutputStream(emlFile); + BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream, bufferSize); + // 从邮件的输入流读取内容,并写入到本地文件 + byte[] buffer = new byte[bufferSize]; + int bytesRead; + while ((bytesRead = bufferedInputStream.read(buffer)) != -1) { + bufferedOutputStream.write(buffer, 0, bytesRead); + } + + // 关闭流 + bufferedInputStream.close(); + bufferedOutputStream.close(); } catch (MessagingException | IOException e) { // 下载邮件失败 抛出自定义邮件下载异常 status = EmailLogManager.STATUS_ERROR;