From da9b5607b57fe2571e77a6f046ff2b530091bf59 Mon Sep 17 00:00:00 2001 From: wenyann Date: Thu, 8 Jul 2021 13:57:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E9=82=AE=E4=BB=B6=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=B8=ADSMTP=E8=B4=A6=E5=8F=B7=E6=98=AF=E5=A6=82=E6=9E=9C?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=90=8D=EF=BC=8C=E8=80=8C=E4=B8=8D=E6=98=AF?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E9=82=AE=E4=BB=B6=E5=9C=B0=E5=9D=80=E7=9A=84?= =?UTF-8?q?=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notice/sender/impl/MailNoticeSender.java | 13 ++++++++++--- .../metersphere/service/SystemParameterService.java | 10 +++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/io/metersphere/notice/sender/impl/MailNoticeSender.java b/backend/src/main/java/io/metersphere/notice/sender/impl/MailNoticeSender.java index d688e08b78..85f6542069 100644 --- a/backend/src/main/java/io/metersphere/notice/sender/impl/MailNoticeSender.java +++ b/backend/src/main/java/io/metersphere/notice/sender/impl/MailNoticeSender.java @@ -24,9 +24,16 @@ public class MailNoticeSender extends AbstractNoticeSender { JavaMailSenderImpl javaMailSender = mailService.getMailSender(); MimeMessage mimeMessage = javaMailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); - helper.setFrom(javaMailSender.getUsername()); - LogUtil.info("发件人地址"+javaMailSender.getUsername()); - LogUtil.info("helper"+helper); + //helper.setFrom(javaMailSender.getUsername()); + if (javaMailSender.getUsername().contains("@")) { + helper.setFrom(javaMailSender.getUsername()); + } else { + String mailHost = javaMailSender.getHost(); + String domainName = mailHost.substring(mailHost.indexOf(".") + 1, mailHost.length()); + helper.setFrom(javaMailSender.getUsername() + "@" + domainName); + } + LogUtil.info("发件人地址" + javaMailSender.getUsername()); + LogUtil.info("helper" + helper); helper.setSubject("MeterSphere " + noticeModel.getSubject()); List emails = super.getUserEmails(messageDetail.getUserIds()); String[] users = emails.toArray(new String[0]); diff --git a/backend/src/main/java/io/metersphere/service/SystemParameterService.java b/backend/src/main/java/io/metersphere/service/SystemParameterService.java index c30742bd2a..9d54c75cb7 100644 --- a/backend/src/main/java/io/metersphere/service/SystemParameterService.java +++ b/backend/src/main/java/io/metersphere/service/SystemParameterService.java @@ -112,6 +112,8 @@ public class SystemParameterService { } if (BooleanUtils.toBoolean(hashMap.get(ParamConstants.MAIL.TLS.getValue()))) { props.put("mail.smtp.starttls.enable", "true"); + props.put("mail.smtp.ssl.trust", hashMap.get(ParamConstants.MAIL.SERVER.getValue())); + } props.put("mail.smtp.timeout", "30000"); props.put("mail.smtp.connectiontimeout", "5000"); @@ -127,7 +129,13 @@ public class SystemParameterService { MimeMessageHelper helper = null; try { helper = new MimeMessageHelper(mimeMessage, true); - helper.setFrom(javaMailSender.getUsername()); + if (javaMailSender.getUsername().contains("@")) { + helper.setFrom(javaMailSender.getUsername()); + } else { + String mailHost = javaMailSender.getHost(); + String domainName = mailHost.substring(mailHost.indexOf(".") + 1, mailHost.length()); + helper.setFrom(javaMailSender.getUsername() + "@" + domainName); + } helper.setSubject("MeterSphere测试邮件 "); helper.setText("这是一封测试邮件,邮件发送成功", true); helper.setTo(recipients);