Skip to content

Commit 1419bd4

Browse files
committed
fix(mail): add configurable 'from' address for email sending
1 parent 3c33ca3 commit 1419bd4

3 files changed

Lines changed: 6 additions & 2 deletions

File tree

.github/workflows/workflow-selfhosted.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ jobs:
1212

1313
steps:
1414
- uses: actions/checkout@v4
15-
1615
- name: Verify local Java & Maven
1716
run: |
1817
echo "Java version:"

src/main/java/cn/programcx/foxnaserver/util/MailSenderUtil.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public class MailSenderUtil {
1818
@Value("${spring.mail.username}")
1919
private String mailUsername;
2020

21+
@Value("${spring.mail.from}")
22+
private String mailFrom;
23+
2124
@Autowired
2225
private JavaMailSender mailSender;
2326

@@ -30,7 +33,8 @@ public void sendMail(String to, String subject, String content) throws Exception
3033
helper.setTo(to);
3134
helper.setSubject(subject);
3235
helper.setText(content, true); // false 表示发送纯文本,true 表示发送 HTML
33-
helper.setFrom(mailUsername);
36+
String from = mailFrom.isEmpty() ? mailUsername : mailFrom;
37+
helper.setFrom(from);
3438

3539
mailSender.send(message);
3640
logger.info("邮件发送成功: 收件人={}, 主题={}", to, subject);

src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ jwt.expiration=${app.jwt.expiration:86400000}
6262
# Mail Configuration
6363
spring.mail.host=${app.spring.mail.host:smtp.qq.com}
6464
spring.mail.port=${app.spring.mail.port:465}
65+
spring.mail.from=${app.spring.mail.from:}
6566
spring.mail.username=${app.spring.mail.username:}
6667
spring.mail.password=${app.spring.mail.password:}
6768
spring.mail.default-encoding=${app.spring.mail.default-encoding:UTF-8}

0 commit comments

Comments
 (0)