From 0fdcfbe9223ecc7646916f1c31f71f8818362607 Mon Sep 17 00:00:00 2001 From: xiaoguangbin Date: Wed, 21 Feb 2024 08:53:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B0=9D=E8=AF=95=E6=9B=B4=E6=94=B9eml?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E5=88=B0=E6=9C=AC=E5=9C=B0=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=B8=8B=E8=BD=BD=E5=87=BA=E7=8E=B0=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/email/EmailServiceManager.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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;