配置Mandril Heroku Ruby on rails

时间:2015-06-17 00:33:54

标签: ruby-on-rails heroku mandrill

我一直在努力为heroku配置邮件发件人, sendgrid是不可能的,现在我正在尝试使用Mandril。 它说我必须把这个代码,但我不知道在哪里,任何消化?

require 'mandrill'
m = Mandrill::API.new # All official Mandrill API clients will automatically pull your API key from the environment
rendered = m.templates.render 'MyTemplate', [{:name => 'main', :content => 'The main content block'}]
puts rendered['html'] # print out the rendered HTML

这是我的日志:

2015-06-17T01:01:50.949397+00:00 app[web.1]:   vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
2015-06-17T01:01:50.949399+00:00 app[web.1]:   vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
2015-06-17T01:01:50.949400+00:00 app[web.1]: 
2015-06-17T01:01:50.949402+00:00 app[web.1]: 
2015-06-17T01:01:50.957251+00:00 heroku[router]: at=info method=POST path="/users/password"

环境/ production.rb

}

ActionMailer::Base.smtp_settings = {
    :port =>           '587',
    :address =>        'smtp.mandrillapp.com',
    :user_name =>      ENV['mandrilusername'],
    :password =>       ENV['mandrilpass'],
    :domain =>         'heroku.com',
    :authentication => :plain
}
ActionMailer::Base.delivery_method = :smtp

end

这里有任何错误

1 个答案:

答案 0 :(得分:0)

以下是我如何配置ActionMailer通过Heroku上的Mandrill发送。将它粘贴在config / environments / production.rb(或Heroku实例的适当环境)中:

# Send emails through Mandrill
config.action_mailer.default_url_options = { :host => 'example.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address: 'smtp.mandrillapp.com',
  port: 587,
  domain: 'example.com',
  user_name: ENV['MANDRILL_USERNAME'],
  password: ENV['MANDRILL_PASSWORD']
}

然后从命令行设置两个环境变量:

heroku config:set MANDRILL_USERNAME=myusername
heroku config:set MANDRILL_PASSWORD=mypassword