rails email error - 530-5.5.1需要验证。

时间:2012-07-30 15:46:52

标签: ruby-on-rails ruby email smtp actionmailer

尝试从Ruby on Rails发送电子邮件,但得到这个:

SocketError in UsersController#create
getaddrinfo: nodename nor servname provided, or not known

我的environment / development.rb文件有:

  config.action_mailer.smtp_settings = { 
    address: "smtp.gmail.com",
    port: 587,
    domain: "my_company.org",
    authentication: "plain",
    enable_starttls_auto: true,
    user_name: "my_username@my_company.org",
    password: "my_pass"
  }

  config.action_mailer.delivery_method = :smtp

  config.action_mailer.default_url_options = { :host => 'localhost:5000' } 
  # 5000 rather than 3000 as I am using foreman.

2 个答案:

答案 0 :(得分:8)

我使用我的Gmail做了同样的事情,以下是我的配置,如果有效,请尝试查看

  config.action_mailer.default_url_options = { :host => 'localhost:3000' }
  ActionMailer::Base.smtp_settings = {
                    :address        => "smtp.gmail.com",
                    :port           => 587,
                    :authentication => :plain,
                    :user_name      => "<my gmail>@gmail.com",
                    :password       => "<my gmail password>",
                    :openssl_verify_mode  => 'none'
  } 

请注意

:openssl_verify_mode  => 'none'

部分跳过SSL错误。

但抱歉,我不知道错误是什么,可能您尝试将Gmail SMTP服务器与其他域名一起使用。

答案 1 :(得分:0)

如果其他人遇到相同的问题,我只是想补充一下,尝试在Rails API中使用gmail实现邮件系统时,我遇到了完全相同的问题,而添加:openssl_verify_mode => 'none'并不能解决我的问题。

相反,安装figaro gem,然后像下面这样在application.yml中添加我的环境变量:

gmail_username: "myemail@gmail.com"
gmail_password: "mypassword"

帮了我大忙。

(并且不要忘记更改您的SMTP设置:)

user_name:             ENV['gmail_username'],
password:              ENV['gmail_password'],