在测试环境中为Mandrill配置rails应用程序

时间:2014-10-29 20:21:47

标签: ruby-on-rails ruby actionmailer mandrill

我正在开发一个使用Mandrill生成电子邮件的Rails应用程序。我不能为我的生活让它在测试环境中工作!我希望能够使用ActionMailer方法来传递,阅读和解析电子邮件,但我一直得到:Errno::ECONNREFUSED: Connection refused - connect(2)

message.rb:

class Message < ActionMailer::Base
  require 'mandrill'
  default from: "My App <messages@myapp.com>"

  def send_welcome_email(to_user)
    mandrill = Mandrill::API.new ENV['MANDRILL_API_KEY']
    template = mandrill.templates.render "welcome-to-myapp", [], [
      {:name => 'username', :content => to_user.name},
      {:name => 'subject', :content => "Welcome to MyApp, #{to_user.name}"}
    ]
    @body = template['html']
    mail(:subject => "Welcome to MyApp, #{to_user.name}", :to => to_user.email, "tags" => ["In Trial - Welcome"],)
    headers['X-MC-Track'] = "opens"
    headers['X-MC-Tags'] ="invite_sent"
  end

end

production.rb

# Mailer configurations

  config.action_mailer.default_url_options = { :protocol => 'https', :host => 'app.myapp.com' }

  ActionMailer::Base.smtp_settings = {
    :address   => "smtp.mandrillapp.com",
    :port      => 25, # ports 587 and 2525 are also supported with STARTTLS
    :enable_starttls_auto => true, # detects and uses STARTTLS
    :user_name => ENV['MANDRILL_USERNAME'],
    :password  => ENV['MANDRILL_API_KEY'], # SMTP password is any valid API key
    :authentication => 'login', # Mandrill supports 'plain' or 'login'
    :domain => 'myapp.com', # your domain to identify your server when connecting
  }

test.rb

ActionMailer::Base.smtp_settings = {
   :address   => "smtp.mandrillapp.com",
   :port      => 25, # ports 587 and 2525 are also supported with STARTTLS
   :enable_starttls_auto => true, # detects and uses STARTTLS
   :user_name => ENV['MANDRILL_USERNAME'],
   :password  => ENV['MANDRILL_API_KEY_TEST'], # SMTP password is any valid API key
   :authentication => 'login', # Mandrill supports 'plain' or 'login'
   :domain => 'myapp.com', # your domain to identify your server when connecting
 }

 config.action_mailer.default_url_options = { :host => '192.168.11.44:3000' }
 config.action_mailer.delivery_method = :smtp

1 个答案:

答案 0 :(得分:0)

检查您用于连接mandrill的端口。它应该是2525或587。

我认为这个问题与你的问题相同:Can't get Mandrill to send emails from Rails App