【发布时间】:2012-02-17 17:47:38
【问题描述】:
尝试在application.conf配置smtp
mail.smtp.host=smtp.sendgrid.net
mail.smtp.user=${SENDGRID_USERNAME}
mail.smtp.pass=${SENDGRID_PASSWORD}
在控制器中
MultiPartEmail email = new MultiPartEmail();
//... setting from,to,subject,content...
Mail.send(email); //using Play's util
但出现异常,在验证 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
【问题讨论】:
-
这个错误是在
git push时间吗?如果是这样,您可以忽略它。您是否收到来自Mail.send()的异常? -
git push没有错误,只是警告。例外是来自Mail.send()说用户凭据错误。我试过如果我直接在代码中使用System.getenv("SENDGRID_USERNAME")并使用MultipartEmail的send,它可以发送。但在那种情况下,我无法使用内置邮件模拟在本地进行测试。
标签: heroku playframework sendgrid