新增发送Email的逻辑

This commit is contained in:
巴拉迪维 2021-09-16 11:18:15 +08:00
parent 66b09f16c7
commit a504e3634b
3 changed files with 47 additions and 0 deletions

View File

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

View File

@ -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

View File

@ -67,11 +67,18 @@
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>${springboot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<version>${springboot.version}</version>
</dependency>
</dependencies>
</project>