新增发送Email的逻辑
This commit is contained in:
parent
66b09f16c7
commit
a504e3634b
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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
|
7
pom.xml
7
pom.xml
|
@ -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>
|
Loading…
Reference in New Issue