这是我第一次尝试使用Heroku发送电子邮件,我非常困惑如何配置所有内容。我已经看了好几个小时了,但仍然无法弄清楚为什么我没有收到电子邮件。我已经在网上到处寻找,但似乎找不到我的配置有什么问题。
如果有人能给予帮助,我将不胜感激。
我的product.rb
文件:
config.action_mailer.default_url_options = { :host => 'acebros.herokuapp.com' }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
address: 'smtp.sendgrid.net',
port: '587',
authentication: "plain",
user_name: ENV['SENDGRID_USERNAME'],
password: ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com',
:enable_starttls_auto => true
}
config.action_mailer.delivery_method = :smtp
一个邮件发送器示例:
default from: "acebrosdev@gmail.com"
def quote_email(user, quote)
@customer = user
@quote = quote
@url = 'acebros.herokuapp.com/' + quote_status_path(@quote)
#attachments['quote.pdf'] = WickedPdf.new.pdf_from_string(
#render_to_string(:pdf => 'quote', :template =>
#'quotes/quote_attachment.html.erb')
#)
mail(to: @customer.email, subject: "Quote ID: ##{@quote.id}")
end
最后,这是我的Heroku日志:
2014-12-08T17:56:38.121051+00:00 app[web.1]: Started POST "/quotes/5/done" for 129.31.193.143 at 2014-12-08 17:56:38 +0000
2014-12-08T17:56:38.241873+00:00 app[web.1]: Rendered quote_mailer/quote_email.text.erb (0.4ms)
2014-12-08T17:56:39.684236+00:00 app[web.1]: Redirected to http://acebros.herokuapp.com/quotes/5
2014-12-08T17:56:39.683035+00:00 app[web.1]: Sent mail to annikamonari@gmail.com (1093.2ms)
2014-12-08T17:56:39.683029+00:00 app[web.1]:
2014-12-08T17:56:39.684436+00:00 app[web.1]: Completed 302 Found in 1560ms (ActiveRecord: 26.9ms)
2014-12-08T17:56:39.692999+00:00 heroku[router]: at=info method=POST path="/quotes/5/done" host=acebros.herokuapp.com request_id=0c19e839-1d20-43ee-9e27-8ba657eb3637 fwd="129.31.193.143" dyno=web.1 connect=2ms service=1572ms status=302 bytes=1246
2014-12-08T17:56:42.352091+00:00 app[web.1]: Processing by QuotesController#show as HTML