Rails 4、如何正确配置smtp设置(gmail) [英] Rails 4, how to correctly configure smtp settings (gmail)

查看:60
本文介绍了Rails 4、如何正确配置smtp设置(gmail)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Rails 4 中创建一个联系表单.我在这里进行了一些挖掘,并且能够使大部分内容发挥作用.(遵循@sethfri 在这里的工作Rails 4 中的联系表单邮件)

I am trying to create a contact form in Rails 4. I did some digging around here and was able to get most of the stuff to work. (followed @sethfri's work here Contact Form Mailer in Rails 4)

现在我可以填写我的表单并点击发送.在我的 rails 服务器中,它说邮件已出站到我的电子邮件地址,但我的 gmail 邮箱中没有收到任何邮件,所以我认为我的 smtp 设置不正确.我的 smtp 设置是:

Right now I am able to fill out my form box and hit send. In my rails server it says the mail was outbound to my email address, but I don't receive anything in my gmail box, so I think my smtp settings aren't right. My smtp settings are:

...config/environments/development.rb

config.action_mailer.raise_delivery_errors = true
  config.action_mailer.perform_deliveries = true

  config.action_mailer.default_url_options = { :host => 'localhost:3000' }

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address => "smtp.gmail.com",
    :port => "587",
    :domain => "mydomain.net",
    :user_name => "mygmailusername@gmail.com",
    :password => "myGmailPassword",
    :authentication => "plain",
    :enable_starttls_auto => true
  } 

我也加入了.../config/initializers/smtp_settings.rb

ActionMailer::Base.smtp_settings = {
    :address => "smtp.gmail.com",
    :port => "587",
    :domain => "mydomain.net",
    :user_name => "gmailuser@gmail.com",
    :password => "gmailPassword",
    :authentication => "plain",
    :enable_starttls_auto => true
}

我错过了什么/做错了什么?我尝试了几件事(将 default_url 更改为端口 1025,将 :port => "587" 更改为 :port => 587)但没有成功.

What am I missing/doing wrong? I've played around with a couple things (changed default_url to port 1025, changed :port => "587" to :port => 587) with no success.

感谢您的帮助!

推荐答案

您必须正确设置域.目前在代码中发布了它的mydomain.net".如果您想通过 Gmail 发送,请将其更改为 gmail.com.

You have to set the domain correctly. Currently in the code posted its "mydomain.net". Change it to gmail.com if you want to sent it via gmail.

config.action_mailer.smtp_settings = {
  address:              'smtp.gmail.com',
  port:                 587,
  domain:               'gmail.com',
  user_name:            'xyz@gmail.com',
  password:             'yourpassword',
  authentication:       :plain,
  enable_starttls_auto: true
}

这篇关于Rails 4、如何正确配置smtp设置(gmail)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆