0
我正在開發使用Rails 4和Ruby 2.0.0的Rails應用程序。 我在我的聯繫頁面中有一個表單,我想從中發送電子郵件給管理員。我選擇與SMTP工作,這是我的配置文件:連接錯誤ActionMailer
# config/initializers/setup_mail.rb
ActionMailer::Base.smtp_settings = {
adress: "smtp.gmail.com",
port: 587,
domain: "gmail.com",
user_name: "[email protected]",
password: "my-gmail-password",
authentication: :plain,
enable_starttls_auto: true
}
ActionMailer::Base.default_url_options[:host] = "localhost:3000"
ActionMailer::Base.raise_delivery_errors = true
這裏是我的郵件控制器:
# mailers/user_mailer.rb
class UserMailer < ActionMailer::Base
default from: "[email protected]"
def welcome_email(user)
@user = user
@url = "localhost:3000/signin"
mail(to: user.email,
subject: "Welcome")
end
end
最後,我的郵件視圖:
# app/views/user_mailer/welcome_mailer.html.erb
<h1>Congratulations "#{@user.firstname} #{@user.lastname}"</h1>
當我打開「$> rails console」,我鍵入以下內容:
$> UserMailer.welcome_email(User.first).deliver
鑑於軌道文件http://guides.rubyonrails.org/action_mailer_basics.html,這是我所需要的。不幸的是我有一個連接錯誤:
Sent mail to [email protected] (10.4ms)
Date: Tue, 21 May 2013 23:09:49 +0200
From: [email protected]
To: [email protected]
Message-ID: <519be29...-Mac.local.mail>
Subject: =?UTF-8?Q?Welcome?=
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<h1>Congratulations XXX YYY</h1>=
Errno::ECONNREFUSED: Connection refused - connect(2)
from /usr/local/rvm/rubies/ruby-2.0.0-rc2/lib/ruby/2.0.0/net/smtp.rb:540:in `initialize'
from /usr/local/rvm/rubies/ruby-2.0.0-rc2/lib/ruby/2.0.0/net/smtp.rb:540:in `open'
from /usr/local/rvm/rubies/ruby-2.0.0-rc2/lib/ruby/2.0.0/net/smtp.rb:540:in `tcp_socket'
from /usr/local/rvm/rubies/ruby-2.0.0-rc2/lib/ruby/2.0.0/net/smtp.rb:550:in `block in do_start'
from /usr/local/rvm/rubies/ruby-2.0.0-rc2/lib/ruby/2.0.0/timeout.rb:65:in `timeout'
from /usr/local/rvm/rubies/ruby-2.0.0-rc2/lib/ruby/2.0.0/net/smtp.rb:549:in `do_start'
from /usr/local/rvm/rubies/ruby-2.0.0-rc2/lib/ruby/2.0.0/net/smtp.rb:519:in `start'
from /usr/local/rvm/gems/ruby-2.0.0-rc2/gems/mail-2.5.3/lib/mail/network/delivery_methods/smtp.rb:136:in `deliver!'
from /usr/local/rvm/gems/ruby-2.0.0-rc2/gems/mail-2.5.3/lib/mail/message.rb:2033:in `do_delivery'
from /usr/local/rvm/gems/ruby-2.0.0-rc2/gems/mail-2.5.3/lib/mail/message.rb:229:in `block in deliver'
from /usr/local/rvm/gems/ruby-2.0.0-rc2/gems/actionmailer-4.0.0.beta1/lib/action_mailer/base.rb:456:in `block in deliver_mail'
from /usr/local/rvm/gems/ruby-2.0.0-rc2/gems/activesupport-4.0.0.beta1/lib/active_support/notifications.rb:158:in `block in instrument'
from /usr/local/rvm/gems/ruby-2.0.0-rc2/gems/activesupport-4.0.0.beta1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
from /usr/local/rvm/gems/ruby-2.0.0-rc2/gems/activesupport-4.0.0.beta1/lib/active_support/notifications.rb:158:in `instrument'
from /usr/local/rvm/gems/ruby-2.0.0-rc2/gems/actionmailer-4.0.0.beta1/lib/action_mailer/base.rb:454:in `deliver_mail'
from /usr/local/rvm/gems/ruby-2.0.0-rc2/gems/mail-2.5.3/lib/mail/message.rb:229:in `deliver'
from (irb):1
from /usr/local/rvm/gems/ruby-2.0.0-rc2/gems/railties-4.0.0.beta1/lib/rails/commands/console.rb:88:in `start'
from /usr/local/rvm/gems/ruby-2.0.0-rc2/gems/railties-4.0.0.beta1/lib/rails/commands/console.rb:9:in `start'
from /usr/local/rvm/gems/ruby-2.0.0-rc2/gems/railties-4.0.0.beta1/lib/rails/commands.rb:64:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'2.0.0dev :002 >
你知道這個錯誤可能來自哪裏嗎?以及如何解決它?
謝謝你的幫助。