使用Ruby发送电子邮件

时间:2010-12-23 08:37:18

标签: ruby-on-rails ruby ruby-on-rails-3

尝试发送电子邮件时出现以下错误。

 Errno::ECONNREFUSED: Connection refused - connect(2)

发送电子邮件的代码

 Reminder.new_event(event_owner.email).deliver!

我的电子邮件设置

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address => "smtp.gmail.com",
    :port => 587,
    :domain => "google.com",
    :authentication =>"login",
    :user_name => "email address",
    :password => "password",
    :enable_starttls_auto => true
  }
你能帮我吗?感谢

3 个答案:

答案 0 :(得分:4)

尝试

config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "google.com",
:authentication =>"plain",
:user_name => "email address",
:password => "password",
}

请注意:

:authentication =>"plain",

:enable_starttls_auto => true

是默认值,无需指定。

答案 1 :(得分:1)

在config / application.rb文件中尝试以下操作:

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :address => "smtp.gmail.com",
  :port => 587,
  :domain => "google.com",
  :authentication =>"plain",
  :user_name => "email address",
  :password => "password",
  :enable_starttls_auto => true
}

要发送电子邮件,请尝试(注意,最后没有!)

Reminder.new_event(event_owner.email).deliver

尝试将测试电子邮件发送到与发送gmail帐户不同的电子邮件地址(因为gmail不允许这样做)。

答案 2 :(得分:0)

我在省略port和:domain时只取得了成功,但必须将:tls设置为true。

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = { 
    :tls => true,
    :address => "smtp.gmail.com", 
    :authentication => :plain, 
    :user_name => "full-email-address", 
    :password => "password" 
  }