fix: 尝试更改eml保存到本地方式解决下载出现失败问题

This commit is contained in:
xiaoguangbin 2024-02-21 08:53:55 +08:00
parent e9c186c9d7
commit 0fdcfbe922

View File

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