问题与Grails邮件插件,连接被拒绝:连接

时间:2014-04-15 14:41:54

标签: grails grails-2.0 grails-plugin

我安装了邮件插件:

grails install-plugin mail

我根据插件添加了我的配置:

grails {
    mail {
      host = "smtp.gmail.com"
      port = 465
      username = "youraccount@gmail.com"
      password = "yourpassword"
      props = ["mail.smtp.auth":"true",
               "mail.smtp.socketFactory.port":"465",
               "mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
               "mail.smtp.socketFactory.fallback":"false"]
    }
}

我将sendMail添加到我的Bootstrap.groovy

class BootStrap {
    def mailService

    def init = { servletContext ->

        try{
            mailService.sendMail {
             from "username@gmail.com"
             to "username@gmail.com"
             subject "Hello"
             body "Mail"
            }
           }catch (Exception e){
            println e
           }
    }
    def destroy = {
    }
}

但是当我执行应用程序时,我得到了

java.net.ConnectException: Connection refused: connect

完整的错误日志

org.springframework.mail.MailSendException: Mail server connection failed; nested exception is com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.gmail.com, 465; timeout -1;
  nested exception is:
    java.net.ConnectException: Connection refused: connect. Failed messages: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.gmail.com, 465; timeout -1;
  nested exception is:
    java.net.ConnectException: Connection refused: connect; message exceptions (1) are:
Failed message 1: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.gmail.com, 465; timeout -1;
  nested exception is:
    java.net.ConnectException: Connection refused: connect

2 个答案:

答案 0 :(得分:1)

重新启动服务器,它将为您服务。当我这样做时,它对我有用。

希望它有所帮助!!

答案 1 :(得分:0)

我只是将一个示例项目推送到github.com/jeffbrown/maildemo,其中包含与发布完全相同的配置,并且它可以正常工作。请参阅Config.groovyBootStrap.groovy

你是否支持可能导致问题的代理?