title: Java Mail Api throws MessagingException: Exception reading response
body: <p>I'm trying to send a mail using localhost and Java Mail Api, however when sending the mail an exception is generated</p>
  
  <pre><code>Exception in thread "main" java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:47)
      at org.springframework.boot.loader.Launcher.launch(Launcher.java:86)
      at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
      at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
  Caused by: javax.mail.MessagingException: Exception reading response;
    nested exception is:
      java.net.SocketTimeoutException: Read timed out
      at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2202)
      at com.sun.mail.smtp.SMTPTransport.close(SMTPTransport.java:1212)
      at javax.mail.Transport.send0(Transport.java:257)
      at javax.mail.Transport.send(Transport.java:124)
      at com.monoplus.mcd.JavaMailApi.sendMail(JavaMailApi.java:87)
      at com.monoplus.mcd.SendMailMain.main(SendMailMain.java:18)
      ... 8 more
  Caused by: java.net.SocketTimeoutException: Read timed out
      at java.net.SocketInputStream.socketRead0(Native Method)
      at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
      at java.net.SocketInputStream.read(SocketInputStream.java:171)
      at java.net.SocketInputStream.read(SocketInputStream.java:141)
      at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:124)
      at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
      at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
      at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:89)
      at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2182)
      ... 13 more
  </code></pre>
  
  <p>My Postfix is running and its configuration is the default.</p>
  
  <p>Also, port 25 is in listening status</p>
  
  <p>And I'm able to connect using <code>telnet localhost 25</code></p>
  
  <p>Source code is at <a href="https://bitbucket.org/saavedrah_/javamail/src/master/" rel="nofollow noreferrer">https://bitbucket.org/saavedrah_/javamail/src/master/</a></p>
  
  <p>Thank you</p>