我想通过Spring Boot发送电子邮件,这是我在aplication.properties中设置此配置的方式:
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.auth=true
spring.mail.host=xxxxx.hostgator.com
spring.mail.port=465
spring.mail.username=XXX@xxxx.com
spring.mail.password=XXXX
spring.mail.protocol=smtp
spring.mail.default-encoding=UTF-8
但是问题是当我用邮递员对其进行测试时,请求始终处于“正在加载”状态:
当我使用gmail帐户测试功能时,它可以正常工作! 我的功能:
public void sendPaimentEmail(String to, String subject, String text) {
MimeMessage message = emailSender.createMimeMessage();
try {
MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setTo(to);
helper.setSubject(subject);
helper.setText(text, true);
FileSystemResource imageSignature = new FileSystemResource(new File(this.pathToSaveFile2 + "logo.png"));
if (null != imageSignature && imageSignature.exists()) {
helper.addInline("logo", imageSignature);
}
FileSystemResource file = new FileSystemResource(new File(this.pathToSaveFile2 + "historique.png"));
helper.addAttachment("Invoice", file);
this.emailSender.send(message);
} catch (Exception e) {
e.printStackTrace();
}
}