2012-02-17 59 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