从Heroku上的Grails 2.0应用程序发送带有Sendgrid的邮件

时间:2011-12-22 18:45:43

标签: email grails heroku sendgrid

我正在尝试通过Heroku上的Sendgrid从我的Grails 2.0应用程序发送电子邮件,但我找不到正确的配置。我一直得到“拒绝连接”的例外:

java.net.ConnectException: Connection refused
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:327)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:193)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)
at java.net.Socket.connect(Socket.java:546)
at java.net.Socket.connect(Socket.java:495)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:233)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1359)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
at javax.mail.Service.connect(Service.java:288)
at grails.plugin.mail.MailMessageBuilder.sendMessage(MailMessageBuilder.groovy:102)
at grails.plugin.mail.MailService.sendMail(MailService.groovy:39)
at MailGrailsPlugin$_configureSendMail_closure6.doCall(MailGrailsPlugin.groovy:149)

我尝试的最新配置如下:

grails {
    mail {
        host = "smtp.sendgrid.net"
        port = 587
        username = System.env.SENDGRID_USERNAME
        password = System.env.SENDGRID_PASSWORD
        props = [
                "mail.smtp.protocol":"smtps",
                "mail.smtp.channel":"plain",
                "mail.smtp.auth":"true",
                "mail.debug":"true"
        ]
    }
}

2 个答案:

答案 0 :(得分:2)

看起来您可能有防火墙或ISP阻止端口587.请尝试:http://support.sendgrid.com/entries/131119-help-smtp-port-25-is-being-blocked

Elmer Thomas,SendGrid.com的开发者传播者

答案 1 :(得分:0)

实际上,问题来自我的Grails配置。出于某种原因,我的邮件配置在某些时候被重置,我在Config.groovy中的内容没有被使用。所以该应用程序试图通过localhost发送电子邮件,但这不起作用。我找到了解决这个问题的方法,但我还不明白为什么会这样。