2012-02-17 58 views
1

试图在application.confheroku玩!与sendgrid配置

mail.smtp.host=smtp.sendgrid.net 
mail.smtp.user=${SENDGRID_USERNAME} 
mail.smtp.pass=${SENDGRID_PASSWORD} 

和Controller

MultiPartEmail email = new MultiPartEmail(); 
//... setting from,to,subject,content... 
Mail.send(email); //using Play's util 

但异常发生时配置SMTP,认证的SMTP服务器时,说不好的用户凭据。

有一两件事我注意到的是,当推到的Heroku和启动应用程序,它会发出警告:

WARNING: Cannot replace SENDGRID_USERNAME in configuration (mail.smtp.user=${SENDGRID_USERNAME}) 
    WARNING: Cannot replace ENV_SENDGRID_PASSWORD in configuration (mail.smtp.pass=${SENDGRID_PASSWORD}) 

这可能是由于预编译标志是,当部署?这里是我的Procfile

web: play run --http.port=$PORT --%prod 
+0

这是'git push'时间的错误吗?如果是这样,你可以忽略它。你是否收到'Mail.send()'的异常? – 2012-02-17 20:08:21

+0

'git push'没有错误,只是警告。 “Mail.send()”例外是来自不良用户凭证。我试过,如果我直接在代码中使用'System.getenv(“SENDGRID_USERNAME”)'并使用'MultipartEmail'的'send',它可以发送。但在这种情况下,我无法使用内置的邮件模拟器进行本地测试。 – jackysee 2012-02-18 23:49:25

回答

4

我创建了一个简单的播放+ SendGrid + Heroku的例子,对我的作品:
https://github.com/jamesward/playsendgrid

我不知道这是什么例子和你的代码之间的不同。我上面注意到的唯一奇怪的事情是它说ENV_SENDGRID_PASSWORD。也许这个环境变量名称是错误的。

+0

有没有办法使用Play!配置使用API​​密钥而不是密码发送EMail? – AHH 2017-06-01 10:08:08