我正在尝试通过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"
        ]
    }
}

最佳答案

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

SendGrid.com的开发布道者Elmer Thomas

09-25 20:12