[英]Wrong “Default From” value in Rails Mailer leads to SMTP error on Heroku with SendGrid
我正在使用Heroku和SendGrid設置Mail並在嘗試使用Rails發送電子郵件時遇到以下錯誤:
Net::SMTPFatalError (550 Cannot receive from specified address <my-email@domain.com>: Unauthenticated senders not allowed
2013-06-01T10:52:34.767516+00:00 app[web.1]: app/controllers/api/v1/post_controller.rb:84:in `reply'
該域“ my-email@domain.com”來自我的郵件程序中的“默認來源”字段:
class NotificationMailer < ActionMailer::Base
default from: "my-email@domain.com"
def post_notification_email(params)
# Send mail here
end
end
我的大問題是我不知道要在此處填寫什么。 這應該是我的電子郵件地址嗎? 一定是我的域名嗎? 是我的Heroku電子郵件嗎? 我的SendGrid電子郵件? 不知道該怎么做才能使SendGrid開心。 刪除此行並希望可以填充的內容也會導致錯誤。 我被卡住了。 其他人使用什么作為“默認來源”?
以防萬一,這又是一件很重要的事情:這一切仍在開發中,因此我尚未將其連接到某個域。 我還沒有真正創建一個SendGrid帳戶,只是將SendGrid附加組件添加到了我在Heroku上的應用程序中。
更新:為生產發布我的動作郵件程序配置:
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '25',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'domain.com',
:enable_starttls_auto => true
}
驗證您的action_mailer配置正確,( config / production.rb ):
# Sendgrid
config.action_mailer.smtp_settings = {
address: "smtp.sendgrid.net",
port: 25,
domain: "example.com",
authentication: "plain",
user_name: ENV["SENDGRID_USERNAME"],
password: ENV["SENDGRID_PASSWORD"]
}
不要忘記更改domain參數! 將sendgrid添加到您的heroku應用程序,如下所示(在您的終端中):
heroku addons:add sendgrid:starter
提交更改並將您的應用程序部署到heroku。 您應該能夠從先前定義的域發送電子郵件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.