【发布时间】:2014-12-25 17:21:32
【问题描述】:
我正在开发一个使用 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
【问题讨论】:
-
您是否在 mandrill api 中添加了 ip 阻止?也许您将其修复到您的生产服务器并且来自其他 ip 的请求被阻止。
标签: ruby-on-rails ruby actionmailer mandrill