From 687c1b22664dcca9490480a06f77b42f907f3a37 Mon Sep 17 00:00:00 2001 From: Tienyu Yang Date: Sun, 24 Mar 2024 21:44:07 +0800 Subject: [PATCH] Add configuration option for email sender address apart from SMTP username (#5351) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind bug /kind api-change #### What this PR does / why we need it: As described in #5350, when using Amazon SES, for example, as email provider, SMTP username for authentication may not exactly match sender email address. When this happens, websites using Halo will not be able to send emails due to invalid addresses that Halo put in SMTP requests. This PR adds a configuration field for those who got a non-email-address username to specify one separately. #### Which issue(s) this PR fixes: Fixes #5350 #### Special notes for your reviewer: #### Does this PR introduce a user-facing change? Yes ```release-note action required 添加了“发送邮件地址”配置项。如果你的 username 是邮件地址,那么忽略这一栏即可;如果不是,那么请在这里填上你希望使用的发件人地址 ``` --- .../run/halo/app/notification/EmailNotifier.java | 12 +++++++++++- .../src/main/resources/extensions/notification.yaml | 5 +++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/application/src/main/java/run/halo/app/notification/EmailNotifier.java b/application/src/main/java/run/halo/app/notification/EmailNotifier.java index 47d3a8728..0a49e2298 100644 --- a/application/src/main/java/run/halo/app/notification/EmailNotifier.java +++ b/application/src/main/java/run/halo/app/notification/EmailNotifier.java @@ -88,7 +88,7 @@ public class EmailNotifier implements ReactiveNotifier { return mimeMessage -> { MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, StandardCharsets.UTF_8.name()); - helper.setFrom(emailSenderConfig.getUsername(), emailSenderConfig.getDisplayName()); + helper.setFrom(emailSenderConfig.getSender(), emailSenderConfig.getDisplayName()); helper.setSubject(payload.getTitle()); helper.setText(payload.getRawBody(), payload.getHtmlBody()); @@ -166,6 +166,7 @@ public class EmailNotifier implements ReactiveNotifier { private String host; private Integer port; private String encryption; + private String sender; /** * Gets email display name. @@ -175,5 +176,14 @@ public class EmailNotifier implements ReactiveNotifier { public String getDisplayName() { return StringUtils.defaultIfBlank(displayName, username); } + + /** + * Gets email sender address. + * + * @return sender if not blank, otherwise username. + */ + public String getSender() { + return StringUtils.defaultIfBlank(sender, username); + } } } diff --git a/application/src/main/resources/extensions/notification.yaml b/application/src/main/resources/extensions/notification.yaml index 3fd11c919..15eaf1954 100644 --- a/application/src/main/resources/extensions/notification.yaml +++ b/application/src/main/resources/extensions/notification.yaml @@ -28,6 +28,11 @@ spec: label: "用户名" name: username validation: required + - $formkit: text + if: "$enable" + label: "发信地址" + name: "sender" + help: "如果用户名为实际发信地址,可忽略" - $formkit: password if: "$enable" label: "密码"