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