title: Grails Mail MessagingException: Could not connect to SMTP host: xxx, port: 25, response: 421
body: <p>I used the unsecured email server (not ssl).</p>
  
  <p>I found that 421 is for: 421 - The service is not available and the connection will be closed.</p>
  
  <p>Grails email plugin configuration:</p>
  
  <pre><code>grails {
  mail {
      host = "xxx.xxx"
      port = 25
      username = "username"
      password = "secret"
  
      props = ["mail.smtp.auth": "true",
              "mail.smtp.socketFactory.port": "25"
      ]
  }}
  </code></pre>
  
  <p>And the exception I got is:</p>
  
  <pre><code>Error Exception in thread "Thread-34" 
  | Error org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: xxx.xxx.xxx, port: 25, response: 421. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: xxx.xxx.xxx, port: 25, response: 421; message exception details (1) are:
  | Error Failed message 1:
  | Error javax.mail.MessagingException: Could not connect to SMTP host: xxx.xxx.xxx, port: 25, response: 421
  | Error     at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1694)
  | Error     at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:525)
  | Error     at javax.mail.Service.connect(Service.java:291)
  | Error     at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:389)
  | Error     at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:340)
  | Error     at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:336)
  | Error     at org.springframework.mail.javamail.JavaMailSender$send$0.call(Unknown Source)
  | Error     at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
  | Error     at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
  | Error     at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
  | Error     at grails.plugin.mail.MailMessageBuilder.sendMessage(MailMessageBuilder.groovy:104)
  | Error     at grails.plugin.mail.MailMessageBuilder$sendMessage$0.call(Unknown Source)
  | Error     at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
  | Error     at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
  | Error     at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
  | Error     at grails.plugin.mail.MailService.sendMail(MailService.groovy:41)
  | Error     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  | Error     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  | Error     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  | Error     at java.lang.reflect.Method.invoke(Method.java:606)
  | Error     at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
  | Error     at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
  | Error     at groovy.lang.MetaMethod$doMethodInvoke.call(Unknown Source)
  | Error     at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
  | Error     at groovy.lang.MetaMethod$doMethodInvoke.call(Unknown Source)
  | Error     at GrailsMelodyGrailsPlugin$_closure4_closure16_closure17.doCall(GrailsMelodyGrailsPlugin.groovy:184)
  | Error     at sun.reflect.GeneratedMethodAccessor488.invoke(Unknown Source)
  | Error     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  | Error     at java.lang.reflect.Method.invoke(Method.java:606)
  | Error     at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
  | Error     at org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod.invoke(ClosureMetaMethod.java:80)
  | Error     at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1108)
  | Error     at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:910)
  | Error     at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39)
  | Error     at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
  | Error     at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
  | Error     at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
  </code></pre>