我正在尝试从我的 spring 应用程序发送一封邮件,内容是使用 jhipster 1.1.0 生成的。我的 spring-boot 版本是 1.5.2
我有这个代码:
应用程序-dev.yml:
spring:
mail:
host: smtp.gmail.com
port: 587
username: myuser@gmail.com
password: mypass
protocol: smtp
tls: true
properties.mail.smtp:
auth: true
starttls.enable: true
#ssl.trust: smtp.gmail.com
starttls.required: true
jhipster:
mail: # specific JHipster mail property, for standard properties see MailProperties
from: myuser@gmail.com
base-url: http://127.0.0.1:8080
Run Code Online (Sandbox Code Playgroud)
邮件服务程序
package com.pfg.easyschedule.service;
import com.pfg.easyschedule.domain.User;
import io.github.jhipster.config.JHipsterProperties;
import org.apache.commons.lang3.CharEncoding;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.mail.MailProperties;
import org.springframework.context.MessageSource;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.thymeleaf.context.Context;
import org.thymeleaf.spring4.SpringTemplateEngine;
import …Run Code Online (Sandbox Code Playgroud)