使用gmail在rails中发送smtp

cyc*_*e87 0 ruby email ruby-on-rails actionmailer

我正在尝试在开发模式下发送激活电子邮件,我使用application.yml输入我的smtp凭据不确定我缺少什么但由于某种原因我无法发送激活电子邮件.这里是

application.yml

SMTP_PORT: 587
  SMTP_DOMAIN: localhost:3000
  SMTP_ADDRESS: smtp.gmail.com
  SMTP_USERNAME: myemail@gmail.com
  SMTP_PASSWORD: myemailpassword
  SMTP_AUTHENTICATION: 'plain'
  enable_starttls_auto: true
Run Code Online (Sandbox Code Playgroud)

development.rb

  config.action_mailer.raise_delivery_errors = false

  config.action_mailer.delivery_method = :file
  config.action_mailer.file_settings = { location: 'tmp/mails' }

  config.action_mailer.default_url_options = { :host => ENV["URL_HOST"] }
Run Code Online (Sandbox Code Playgroud)

token_mailer.rb

  def activation(email, token)
    @token_url = edit_activation_url token
    mail to: email
  end
Run Code Online (Sandbox Code Playgroud)

San*_*Myh 6

在development.rb中使用它

config.action_mailer.delivery_method = :smtp

config.action_mailer.smtp_settings = {
     :address => "smtp.gmail.com",
     :port => 587,
     :user_name => "your mail",
     :password => "your password",
     :authentication => :plain,
     :enable_starttls_auto => true
}
Run Code Online (Sandbox Code Playgroud)

  • 现在在2017年您必须激活关于不安全应用的选项https://myaccount.google.com/lesssecureapps启用此选项,它是全部 (2认同)