代码之家  ›  专栏  ›  技术社区  ›  Hedge

Rails Action Mailer不发送邮件

  •  5
  • Hedge  · 技术社区  · 15 年前

    我试着用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"
    
    3 回复  |  直到 15 年前
        1
  •  3
  •   apneadiving    15 年前

    我想,你的域参数是错误的。 我在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  }
    
        2
  •  0
  •   Fusco    15 年前
        3
  •  0
  •   d sharpe    14 年前

    这就是我成功使用的

    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"
    
        4
  •  0
  •   Eduardo Baitello Rutabaga Man    7 年前

    在我的项目中,我使用这些行并成功运行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. 将身份验证更改为:登录