2014-10-29 98 views
0

我正在使用Mandrill生成電子郵件的Rails應用程序。我不能在我的生活中讓它在測試環境中工作!我希望能夠使用的ActionMailer方法來實現,讀取和解析電子郵件,但我不斷收到:Errno::ECONNREFUSED: Connection refused - connect(2)在測試環境中爲Mandrill配置Rails應用程序

message.rb:

class Message < ActionMailer::Base 
    require 'mandrill' 
    default from: "My App <[email protected]>" 

    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

你給mandrill api添加了一個ip阻塞嗎?也許你將它修復到你的生產服務器上,並且來自其他ips的請求被阻止。 – tebayoso 2014-10-29 20:23:04

回答

相關問題