Java 使用Spring Boot发送电子邮件
我有一个带有From/Tp输入字段和TextArea作为框的表单。我想用Spring Boot发送电子邮件。如何使用Spring Boot发送电子邮件 谢谢你的回答。现在可以了 那是我的控制器Java 使用Spring Boot发送电子邮件,java,spring-boot,Java,Spring Boot,我有一个带有From/Tp输入字段和TextArea作为框的表单。我想用Spring Boot发送电子邮件。如何使用Spring Boot发送电子邮件 谢谢你的回答。现在可以了 那是我的控制器 @Controller @RequestMapping("/sendmail") public class MailController { @Autowired private MailService mailService; @RequestMapping(method =
@Controller
@RequestMapping("/sendmail")
public class MailController {
@Autowired
private MailService mailService;
@RequestMapping(method = RequestMethod.POST)
private String sendMail(HttpServletRequest request) {
String covere = request.getParameter("covere");
try {
mailService.sendMail(covere);
return "apply";
} catch (MailException e) {
e.printStackTrace();
}
return "apply";
}
}
这是我的服务
@Component
public class MailService {
@Autowired
private JavaMailSender javaMailSender;
public void sendMail(String covere) throws MailException{
SimpleMailMessage mail = new SimpleMailMessage();
mail.setTo("yottiallipierre@gmail.com");
mail.setFrom("yottiallipierre@gmail.com");
mail.setSubject("Test");
mail.setText(covere);
javaMailSender.send(mail);
}
}
那是我的财产档案
spring.mail.host = smtp.gmail.com
spring.mail.port= 465
spring.mail.username = yottiallipierre@gmail.com
spring.mail.password = losangeles4004*
send.from.email= yottiallipierre@gmail.com
spring.mail.properties.mail.smtp.auth = true;
spring.mail.properties.mail.smtp.starttls.enable = true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.ssl.enable = true
spring.mail.properties.mail.socketFactory.port=587
spring.mail.properties.mail.socketFactory.class=javax.net.ssl.SSLSocketFactory
spring.mail.properties.mail.socketFactory.fallback=false
提前感谢对兄弟没有帮助。显示您尝试过的代码,我们可以帮助您解决错误。您检查了以下内容:?