[英]Configuring rails app for Mandrill in Test environment
我正在使用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
檢查您用於連接山rill的端口。 它應該是2525或587。
我認為這個問題與您的問題相同: 無法讓Mandrill從Rails App發送電子郵件 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.