前提・実現したいこと
javaのフレームワークSpringBootでメール送信するプログラムを作りたいです。
使っているライブラリは
org.springframework.mail.MailSender
org.springframework.mail.SimpleMailMessage
で、application.propertiesに以下の設定をしています。
#mail send test spring.mail.host=localhost spring.mail.port=2525 spring.mail.username=test spring.mail.password=pass spring.mail.properties.mail.smtp.auth=false spring.mail.properties.mail.smtp.starttls.enable=false spring.mail.default-encoding=UTF-8 spring.mail.protocol=smtp spring.mail.properties.mail.smtp.auth=false spring.mail.properties.mail.smtp.starttls.enable=false
発生している問題・エラーメッセージ
MailSender.send('hoge');でメール送信すると、以下のエラーになってしまいます。
org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.NoSuchProviderException: No provider for SMTP. Failed messages: javax.mail.NoSuchProviderException: No provider for SMTP; message exceptions (1) are: Failed message 1: javax.mail.NoSuchProviderException: No provider for SMTP] with root cause
該当のソースコード
Pom.xml
xml
1 <parent> 2 <groupId>org.springframework.boot</groupId> 3 <artifactId>spring-boot-starter-parent</artifactId> 4 <version>1.5.2.RELEASE</version> 5 <relativePath /> <!-- lookup parent from repository --> 6 </parent> 7... 8 <dependency> 9 <groupId>org.springframework.boot</groupId> 10 <artifactId>spring-boot-starter-mail</artifactId> 11 </dependency> 12 13<build> 14 <plugins> 15 <plugin> 16 <groupId>org.springframework.boot</groupId> 17 <artifactId>spring-boot-maven-plugin</artifactId> 18 <configuration> 19 <archive> 20 <manifest> 21 <mainClass>hoge.fugaApplication</mainClass> 22 <addClasspath>true</addClasspath> 23 </manifest> 24 <manifestEntries> 25 <Class-Path>./config</Class-Path> 26 </manifestEntries> 27 </archive> 28 </configuration> 29 </plugin> 30 </plugins> 31</build> 32... 33
java
1import org.springframework.mail.MailSender; 2import org.springframework.mail.SimpleMailMessage; 3 4public class MailService{ 5 6 @Autowired MailSender sender; 7 8 public void sendMail(String to, String subject, String message) { 9 10 SimpleMailMessage msg = new SimpleMailMessage(); 11 msg.setFrom('hogehoge@mail.com'); 12 msg.setTo(to); 13 msg.setSubject(subject); //タイトルの設定 14 msg.setText(message); //本文の設定 15 16 this.sender.send(msg); 17 } 18}
試したこと
デバッグモードにして、送信直前のsenderの中身を確認しました。
sender.javaMailProperties は{}でした。。
application.propertiesで設定した値が、取得できていないようです。
補足情報(FW/ツールのバージョンなど)
SMTPは疑似的にFakeSMTP Serverを起動して使っています。
https://github.com/Nilhcem/FakeSMTP
ネットで見たところ、sender.javaMailPropertiesに値は自動的にセットされるので、
propertiesに書くだけでよいのかと思っているのですが、環境のせいなのか原因がわかりません。
お詳しい方にご教示いただきたく、どうぞよろしくお願いいたします。
追記
application.propertiesの設定を環境によって変更できるよう、jarからの相対位置で外部に設定しています。このため、設定が読み込めないようです。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/03/29 11:34
2018/03/29 11:40
2018/03/29 12:39
2018/03/30 02:12