title: javax.mail.MessagingException: [EOF](Spring MVC)
body: <p>I trying to add JavaMail in my web application.</p>
  
  <p><strong>My context:</strong></p>
  
  <pre><code>    &lt;context:property-placeholder location="classpath:mail/gmail.com.properties" ignore-unresolvable="true" /&gt;
  
      &lt;bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"&gt;
          &lt;property name="javaMailProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="mail.smtps.auth"&gt;${mail.smtps.auth}&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
          &lt;property name="host" value="${mail.host}" /&gt;
          &lt;property name="port" value="${mail.port}" /&gt;
          &lt;property name="username" value="${mail.username}" /&gt;
          &lt;property name="password" value="${mail.password}" /&gt;
          &lt;property name="protocol" value="${mail.protocol}" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="templateMessage" class="org.springframework.mail.SimpleMailMessage"&gt;
          &lt;property name="from" value="${mail.from}" /&gt;
          &lt;property name="subject" value="Mail subject" /&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p><strong>My properties:</strong></p>
  
  <pre><code>mail.host=smtp.gmail.com
  mail.port=465
  mail.username=my@gmail.com
  mail.password=my
  mail.from=my@gmail.com
  mail.protocol=smtps
  mail.smtps.auth=true
  </code></pre>
  
  <p><strong>My Service:</strong></p>
  
  <pre><code>@Service
  public class MailServiceImpl implements MailService {
  
      @Autowired
      private MailSender mailSender;
  
      @Override
      public void sendMail(String to, String subject, String body) {
          SimpleMailMessage mailMessage = new SimpleMailMessage();
          mailMessage.setTo(to);
          mailMessage.setText(body);
          try {
              mailSender.send(mailMessage);
          } catch (MailException mailException) {
              mailException.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p><strong>Logs:</strong></p>
  
  <pre><code>org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: [EOF]. Failed messages: javax.mail.MessagingException: [EOF]; message exception details (1) are:
  Failed message 1:
  javax.mail.MessagingException: [EOF]
      at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1363)
      at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:836)
      at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:375)
      at javax.mail.Service.connect(Service.java:275)
      at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:389)
      at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:306)
      at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:296)
      at by.netcracker.artemyev.service.impl.MailServiceImpl.sendMail(MailServiceImpl.java:25)
      at by.netcracker.artemyev.service.impl.UserServiceImpl.addUser(UserServiceImpl.java:67)
      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.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
      at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
      at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
      at com.sun.proxy.$Proxy39.addUser(Unknown Source)
      at by.netcracker.artemyev.web.UserController.registrationUser(UserController.java:59)
      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.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
      at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
      at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
      at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
      at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:475)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
      at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341)
      at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:495)
      at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
      at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:767)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1354)
      at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p><strong><em>In the same time if I trying that:</em></strong></p>
  
  <pre><code>try (GenericXmlApplicationContext context = new GenericXmlApplicationContext()) {
              context.load("classpath:applicationContext.xml");
              context.refresh();
              JavaMailSender mailSender = context.getBean("mailSender", JavaMailSender.class);
              SimpleMailMessage templateMessage = context.getBean("templateMessage", SimpleMailMessage.class);
              SimpleMailMessage mailMessage = new SimpleMailMessage(templateMessage);
              mailMessage.setTo("art15@gmail.com");
              mailMessage.setText("Hello");
              try {
                  mailSender.send(mailMessage);
                  System.out.println("Mail sended");
              } catch (MailException mailException) {
                  System.out.println("Mail send failed.");
                  mailException.printStackTrace();
              }
          }
  </code></pre>
  
  <p><strong><em>I don't have a problem:</em></strong></p>
  
  <p>*Failed message 1:</p>
  
  <p>javax.mail.MessagingException: [EOF]*</p>
  
  <p><strong><em>Why I have problem in my first example? How fix this?</em></strong> </p>