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