我想在用户预订时向他发送电子邮件。为此,我决定尝试向我的两封电子邮件发送一封电子邮件。我看了几个教程,并决定按照视频中的说明进行操作,但有些事情没有解决
我在我的 pom.xml 中添加了这个依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<version>2.3.4.RELEASE</version>
</dependency>
这在 application.properties 中
我将用“XXXXX”(这是电子邮件密码)替换我的密码
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=cinemawebkatrina@gmail.com
spring.mail.password=xxxxxxx
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
这是我的java代码
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("cinemawebkatrina@gmail.com");
message.setTo("ppikursov19@gmail.com");
message.setSubject("Test");
message.setText(strMessage);
emailSender.send(message);
您知道我做错了什么以及为什么我无法发送电子邮件吗?我看到了这个错误“用户名和密码不被接受”。
<块引用>2021-04-04 15:45:57.737 ERROR 6532 --- [nio-8080-exec-6] oaccC[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet]在路径 [] 的上下文中抛出异常 [请求处理失败;嵌套异常是 org.springframework.mail.MailAuthenticationException: Authentication failed;嵌套异常是 javax.mail.AuthenticationFailedException: 535-5.7.8 不接受用户名和密码。在 535 5.7.8 support.google.com/mail/?p=BadCredentials f17sm1431874lfq.175 - gsmtp ] 中了解更多信息以及根本原因
在我的 application.properties
文件中,我是否需要使用电子邮件的用户名和密码?