From 51d47de6deec9990c03d5a373064cb3a61355abf Mon Sep 17 00:00:00 2001 From: Tq Date: Fri, 15 Apr 2022 10:13:13 +0800 Subject: [PATCH] [Bug] [ALERT-9487] change email attachment filename to add random string to avoid issues (#9498) * change email attachment filename to add random string to avoid always use same file * change email attachment filename to add random string to avoid always use same file --- .../dolphinscheduler/plugin/alert/email/MailSender.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailSender.java b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailSender.java index e64b4a7158..a7305cf741 100644 --- a/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailSender.java +++ b/dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-email/src/main/java/org/apache/dolphinscheduler/plugin/alert/email/MailSender.java @@ -38,6 +38,7 @@ import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.UUID; import javax.activation.CommandMap; import javax.activation.MailcapCommandMap; @@ -326,13 +327,15 @@ public final class MailSender { part1.setContent(partContent, EmailConstants.TEXT_HTML_CHARSET_UTF_8); // set attach file MimeBodyPart part2 = new MimeBodyPart(); - File file = new File(xlsFilePath + EmailConstants.SINGLE_SLASH + title + EmailConstants.EXCEL_SUFFIX_XLSX); + // add random uuid to filename to avoid potential issue + String randomFilename = title + UUID.randomUUID(); + File file = new File(xlsFilePath + EmailConstants.SINGLE_SLASH + randomFilename + EmailConstants.EXCEL_SUFFIX_XLSX); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } // make excel file - ExcelUtils.genExcelFile(content, title, xlsFilePath); + ExcelUtils.genExcelFile(content, randomFilename, xlsFilePath); part2.attachFile(file); part2.setFileName(MimeUtility.encodeText(title + EmailConstants.EXCEL_SUFFIX_XLSX, EmailConstants.UTF_8, "B"));