From a504e3634be7ba86c2a14af4169ea16da1dfba28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B7=B4=E6=8B=89=E8=BF=AA=E7=BB=B4?= Date: Thu, 16 Sep 2021 11:18:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8F=91=E9=80=81Email?= =?UTF-8?q?=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification/common/utils/EmailUtils.java | 30 +++++++++++++++++++ executor/src/main/resources/mail.properties | 10 +++++++ pom.xml | 7 +++++ 3 files changed, 47 insertions(+) create mode 100644 common/src/main/java/cn/org/gitlink/notification/common/utils/EmailUtils.java create mode 100644 executor/src/main/resources/mail.properties diff --git a/common/src/main/java/cn/org/gitlink/notification/common/utils/EmailUtils.java b/common/src/main/java/cn/org/gitlink/notification/common/utils/EmailUtils.java new file mode 100644 index 0000000..3ff3a1a --- /dev/null +++ b/common/src/main/java/cn/org/gitlink/notification/common/utils/EmailUtils.java @@ -0,0 +1,30 @@ +package cn.org.gitlink.notification.common.utils; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.PropertySource; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.mail.javamail.MimeMessageHelper; +import org.springframework.stereotype.Service; + +import javax.mail.MessagingException; +import javax.mail.internet.MimeMessage; + +@PropertySource(value = "mail.properties") +@Service(value = "GitlinkMailUtils") +public class EmailUtils { + + @Autowired + private JavaMailSender mailSender; + + public void sendMail(String subject, String recipient, String content) throws MessagingException { + MimeMessage mail = mailSender.createMimeMessage(); + MimeMessageHelper helper = new MimeMessageHelper(mail, true); + helper.setTo(recipient); + helper.setSubject(subject); + helper.setText(content, true); + mailSender.send(mail); + } + + +} diff --git a/executor/src/main/resources/mail.properties b/executor/src/main/resources/mail.properties new file mode 100644 index 0000000..ba4b2cd --- /dev/null +++ b/executor/src/main/resources/mail.properties @@ -0,0 +1,10 @@ +spring.mail.host=smtp.exmail.qq.com +spring.mail.default-encoding=utf-8 +spring.mail.port=465 +spring.mail.username=xxx +spring.mail.password=xxxx +spring.mail.properties[mail.smtp.auth]=true +spring.mail.properties[mail.smtp.connectiontimeout]=10000 +spring.mail.properties[mail.smtp.timeout]=10000 +spring.mail.properties[mail.smtp.writetimeout]=10000 +spring.mail.properties[mail.smtp.starttls.enable]=true \ No newline at end of file diff --git a/pom.xml b/pom.xml index 0501762..93972bd 100644 --- a/pom.xml +++ b/pom.xml @@ -67,11 +67,18 @@ guava 20.0 + org.springframework.boot spring-boot-starter-validation ${springboot.version} + + + org.springframework.boot + spring-boot-starter-mail + ${springboot.version} + \ No newline at end of file