こんにちは。
現在、SpringBootでメール送信機能を作成しており、
ローカルで立てたSMTPサーバ(smtp4devというツール)を利用してのメール送信はうまくいったのですが、
同じLAN内の別の端末上のSMTPサーバを利用してのメール送信がうまくいきません。
メール送信処理が実行されるとき、以下の例外が発生します。
2017-01-11 14:27:27.760 ERROR 3000 --- [nio-8080-exec-7] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.mail.MailSendException: Mail server connection failed; nested exception is com.sun.mail.util.MailConnectException: Couldn't connect to host, port: 10.xx.xx.xx, 25; timeout 50000; nested exception is: java.net.SocketException: Network is unreachable: connect. Failed messages: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: 10.xx.xx.xx, 25; timeout 50000; nested exception is: java.net.SocketException: Network is unreachable: connect; message exceptions (1) are: Failed message 1: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: 10.xx.xx.xx, 25; timeout 50000; nested exception is: java.net.SocketException: Network is unreachable: connect] with root cause java.net.SocketException: Network is unreachable: connect at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
ただし、同じ設定(SMTPホスト、ポート)でOutlookを使用してメールを送信をした場合は成功するため、
ネットワークの問題ではなさそうです。
現在の開発環境とコードは以下のようになっております。
[開発環境]
・eclipse(Luna4.4.0)
・maven(3.2.3)
・SpringBoot(1.2.0)
【application.properties】
spring.mail.default-encoding= UTF-8 spring.mail.protocol= smtp spring.mail.properties.mail.smtp.auth=false spring.mail.host=10.xx.xx.xx spring.mail.port=25 spring.mail.properties.mail.smtp.connectiontimeout=50000 spring.mail.properties.mail.smtp.timeout=50000 spring.mail.properties.mail.smtp.ssl.enable=false spring.mail.properties.mail.smtp.starttls.enable=false
【メール送信クラス(一部抜粋)】
java
1 2import org.springframework.mail.MailSender; 3 4 /** メール送信サービス */ 5 @Autowired 6 MailSender mailSender; 7 8 private void sendMail(){ 9 10 /*****************/ 11 /** メールの作成 */ 12 /*****************/ 13 SimpleMailMessage msg = new SimpleMailMessage(); 14 15 // 送信元 16 msg.setFrom("from@test.co.jp"); 17 18 // 件名 19 msg.setSubject("件名テスト"); 20 21 // 本文 22 String text = ""; 23 text += "テストメールです"; 24 msg.setText(text); //本文の設定 25 26 // 宛先 27 msg.setTo("to@test.co.jp"); 28 29 // 送信 30 mailSender.send(msg); 31 }
分かる方がいらっしゃいましたら、ご教示いただければと思います。
よろしくお願い致します。
あなたの回答
tips
プレビュー