Rails Action Mailer不发送邮件

时间:2010-11-25 08:00:40

标签: ruby-on-rails smtp actionmailer

我正在尝试使用Action Mailer和Googlemail-SMTP服务器通过rails发送邮件,但它不起作用。我做错了什么?

这是我使用的配置(我还尝试了一个没有身份验证的本地中继服务器也没有用):

# Action Mailer config
config.action_mailer.smtp_settings = {
# Gmail Account
:tls => true,
:address => "smtp.googlemail.com",
:port => "587",
:domain => "localhost",
:authentication => :plain,
:user_name => "joijoii@googlemail.com",
:password => "dsgdes" 

config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default_url_options = { :host => "localhost:80" }
config.action_mailer.default_charset = "utf-8"

4 个答案:

答案 0 :(得分:3)

我猜,您的域参数错误。 我在config / initializers目录中编写了一个初始化程序,它看起来像这样:

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.perform_deliveries = true

ActionMailer::Base.smtp_settings = {
  :address              => "smtp.gmail.com",
  :port                 => "587",
  :domain               => 'gmail.com',
  :user_name            => 'joijoii@googlemail.com',
  :password             => 'dsgdes',
  :authentication       => 'plain',
  :enable_starttls_auto => true  }

答案 1 :(得分:0)

:domain => 'YOUR_DOMAIN'

示例http://asciicasts.com/episodes/206-action-mailer-in-rails-3

答案 2 :(得分:0)

这就是我成功使用的

config.action_mailer.smtp_settings = {
  :tls => true ,
  :enable_starttls_auto => true ,
  :authentication => :login ,
  :address => "smtp.gmail.com" ,
  :port => 587 ,
  :domain => "smtp.gmail.com" ,
  :user_name => "youremail@google.com" ,
  :password => "yourpassword"

答案 3 :(得分:0)

在我的项目中,我使用这些行并成功运行了mycode:

config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = smtp
config.action_mailer.smtp_settings = {
address: 'smtp.sendgrid.net',
port: 587, domain: '3SClub.com',
user_name: ENV['SENDGRID_USERNAME'],
password: ENV['SENDGRID_PASSWORD'],
authentication: :plain,
enable_starttls_auto: true
}
config.action_mailer.default_url_options = {:host =>    "localhost:3000"}

注意:

  1. 检查您的域名。

  2. 将身份验证更改为:login