Rails:没有收到联系我们表单的电子邮件

时间:2014-11-08 16:52:56

标签: ruby-on-rails ruby-on-rails-3 email ruby-on-rails-4

我在heroku中有一个应用程序,只是为了测试联系我们是否有效但从未收到过电子邮件,这是我的联系模式

class Contact < MailForm::Base
  attribute :name,      :validate => true
  attribute :email,     :validate => /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
  attribute :message
  attribute :nickname,  :captcha  => true

  # Declare the e-mail headers. It accepts anything the mail method
  # in ActionMailer accepts.
  def headers
    {
      :subject => "My Contact Form",
      :to => "contact@gmail.com",
      :from => %("#{name}" <#{email}>)
    }
  end
end

并且我的production.rb文件

  config.action_mailer.default_url_options = { :host => 'young-river-2391.herokuapp.com' }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = false
  config.action_mailer.default :charset => "utf-8"
  config.action_mailer.smtp_settings = {
    address:              'smtp.gmail.com',
    port:                 587,
    domain:               'gmail.com',
    user_name:            'contact@gmail.com',
    password:             'mypassword',
    authentication:       'plain',
    enable_starttls_auto: true  }

更新: 这是我从控制台获得的内容

2014-11-08T17:35:07.141130+00:00 app[web.1]: Started POST "/contacts" for 105.132.166.163 at 2014-11-08 17:35:07 +0000
2014-11-08T17:35:07.142447+00:00 app[web.1]: Processing by ContactsController#create as HTML
2014-11-08T17:35:07.142452+00:00 app[web.1]: Processing by ContactsController#create as HTML
2014-11-08T17:35:07.142497+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"t152NgJZxX9mIdlRS/CGsxH6lCwg3PDj0UphBnHXOZw=", "contact"=>{"name"=>"name ", "email"=>"name@gmail.com", "message"=>"This is a message", "nickname"=>""}, "commit"=>"Send message"}
2014-11-08T17:35:07.142513+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"t152NgJZxX9mIdlRS/CGsxH6lCwg3PDj0UphBnHXOZw=", "contact"=>{"name"=>"name ", "email"=>"name@gmail.com", "message"=>"This is a message", "nickname"=>""}, "commit"=>"Send message"}
2014-11-08T17:35:07.149561+00:00 app[web.1]:   Rendered vendor/bundle/ruby/2.0.0/gems/mail_form-1.5.0/lib/mail_form/views/mail_form/contact.erb (0.7ms)
2014-11-08T17:35:07.149568+00:00 app[web.1]:   Rendered vendor/bundle/ruby/2.0.0/gems/mail_form-1.5.0/lib/mail_form/views/mail_form/contact.erb (0.7ms)
2014-11-08T17:35:07.141175+00:00 app[web.1]: Started POST "/contacts" for 105.132.166.163 at 2014-11-08 17:35:07 +0000
2014-11-08T17:35:07.417088+00:00 heroku[router]: at=info method=POST path="/contacts" host=young-river-2391.herokuapp.com request_id=7cabe546-1435-4626-a441-01377a668def fwd="105.132.166.163" dyno=web.1 connect=2ms service=281ms status=200 bytes=1719
2014-11-08T17:35:07.414677+00:00 app[web.1]: 
2014-11-08T17:35:07.414680+00:00 app[web.1]: Sent mail to contact@gmail.com (263.7ms)
2014-11-08T17:35:07.414686+00:00 app[web.1]: 
2014-11-08T17:35:07.414687+00:00 app[web.1]: Sent mail to contact@gmail.com (263.7ms)
2014-11-08T17:35:07.415701+00:00 app[web.1]:   Rendered contacts/create.html.erb within layouts/application (0.1ms)
2014-11-08T17:35:07.415706+00:00 app[web.1]:   Rendered contacts/create.html.erb within layouts/application (0.1ms)
2014-11-08T17:35:07.416507+00:00 app[web.1]: Completed 200 OK in 274ms (Views: 1.3ms | ActiveRecord: 0.0ms)
2014-11-08T17:35:07.416512+00:00 app[web.1]: Completed 200 OK in 274ms (Views: 1.3ms | ActiveRecord: 0.0ms)

1 个答案:

答案 0 :(得分:0)

您是否添加了SendGrid或其他一个邮件加载项?这些都是从您的heroku应用程序发送电子邮件所必需的。

请参阅https://devcenter.heroku.com/articles/smtp