【问题标题】:heroku play! with sendgrid configurationheroku 玩!使用 sendgrid 配置
【发布时间】: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")并使用MultipartEmailsend,它可以发送。但在那种情况下,我无法使用内置邮件模拟在本地进行测试。

标签: heroku playframework sendgrid


【解决方案1】:

我创建了一个适合我的简单 Play + SendGrid + Heroku 示例:
https://github.com/jamesward/playsendgrid

我不确定这个示例和您的代码有什么不同。我在上面注意到的唯一奇怪的地方是上面写着ENV_SENDGRID_PASSWORD。也许那个环境变量名是错误的。

【讨论】:

  • 有没有办法使用Play!配置使用 API 密钥而不是密码发送电子邮件?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多