いつもお世話になっております。
今回、springBootを使ってoutlookのメールを送れるメールフォームを作成しようと思い下記の記事を参考に進めていました。↓
https://reasonable-code.com/spring-boot-mail/#i-3
記事通りにやったところgmailの送信は成功したのですがoutlookに当てはめてみるとエラーが起きました。
エラーコードを見ると認証に失敗しましたとあるのでパスワード周りが怪しいそうです。
しかし、パスワードが正しいのは確認したので、パスワードとは別に認証(二段階認証など)が必要なのでしょうか?
もしくはoutlookの場合は別に設定する項目があるのでしょうか?
実行クラス
package com.example.demo.trySpring; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.mail.MailSender; import org.springframework.mail.SimpleMailMessage; @SpringBootApplication public class DemoApplication implements CommandLineRunner { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } private final MailSender mailSender; public DemoApplication(MailSender mailSender) { this.mailSender = mailSender; } @Override public void run(String... args) { SimpleMailMessage msg = new SimpleMailMessage(); msg.setTo("送信先メールアドレス1"); msg.setCc("送信先メールアドレス1"); msg.setBcc("送信先メールアドレス1"); msg.setSubject("件名"); msg.setText("本文"); // メール送信 mailSender.send(msg); } }
application.properties
spring.mail.host=smtp.office365.com spring.mail.port=587 spring.mail.username=送信元メールアドレス spring.mail.password=outlookパスワード spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.starttls.enable=true
エラー内容
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2020-07-14 10:24:39.167 ERROR 12156 --- [ main] o.s.boot.SpringApplication : Application run failed java.lang.IllegalStateException: Failed to execute CommandLineRunner at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:798) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE] at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:779) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE] at com.example.demo.trySpring.DemoApplication.main(DemoApplication.java:13) [classes/:na] Caused by: org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful [TYAP286CA0006.JPNP286.PROD.OUTLOOK.COM] at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:440) ~[spring-context-support-5.2.7.RELEASE.jar:5.2.7.RELEASE] at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:323) ~[spring-context-support-5.2.7.RELEASE.jar:5.2.7.RELEASE] at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:312) ~[spring-context-support-5.2.7.RELEASE.jar:5.2.7.RELEASE] at com.example.demo.trySpring.DemoApplication.run(DemoApplication.java:33) [classes/:na] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:795) [spring-boot-2.3.1.RELEASE.jar:2.3.1.RELEASE] ... 5 common frames omitted Caused by: javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful [TYAP286CA0006.JPNP286.PROD.OUTLOOK.COM] at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:947) ~[jakarta.mail-1.6.5.jar:1.6.5] at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:858) ~[jakarta.mail-1.6.5.jar:1.6.5] at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:762) ~[jakarta.mail-1.6.5.jar:1.6.5] at javax.mail.Service.connect(Service.java:342) ~[jakarta.mail-1.6.5.jar:1.6.5] at org.springframework.mail.javamail.JavaMailSenderImpl.connectTransport(JavaMailSenderImpl.java:518) ~[spring-context-support-5.2.7.RELEASE.jar:5.2.7.RELEASE] at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:437) ~[spring-context-support-5.2.7.RELEASE.jar:5.2.7.RELEASE] ... 9 common frames omitted 2020-07-14 10:24:39.574 INFO 12156 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
あなたの回答
tips
プレビュー