【问题标题】:Mailer not sending emails rails 4邮件程序不发送电子邮件 rails 4
【发布时间】:2014-11-18 08:37:16
【问题描述】:

我的邮件在等待后没有发送任何内容,我不知道为什么。我也试过deliver_now

当我转到 URL http://localhost:3000/send_mail 时,我没有收到任何错误,只是一个空白页。

我的终端状态:

Started GET "/send_mail" for ::1 at 2014-11-18 00:32:39 -0800
Processing by HomeController#send_mail as HTML

ActionMailer::Base#mail: processed outbound mail in 1.2ms

Sent mail to myemail@gmail.com (1.2ms)
Date: Tue, 18 Nov 2014 00:32:39 -0800
From: me@example.com
To: myemail@gmail.com
Message-ID: <546b0427e5677_82b3ffd9e6809bc2363f@MTVL1289dd026.local.mail>
Subject: Contact request
Mime-Version: 1.0
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

test
  Rendered text template (0.0ms)
Completed 200 OK in 4ms (Views: 0.2ms | ActiveRecord: 0.0ms)
::1 - - [18/Nov/2014:00:32:39 -0800] "GET /send_mail HTTP/1.1" 200 - 0.0066

config/environments/development.rb

  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :test
  host = 'localhost:3000'
  config.action_mailer.default_url_options = { host: host }

家庭控制器:

class HomeController < ApplicationController
  def index
  end

  def send_mail
    ActionMailer::Base.mail(:from => "me@example.com", :to => "myemail@gmail.com", :subject => "Contact request", :body => "test").deliver
    render nothing: true
  end
end

routes.rb

match '/send_mail', to: "home#send_mail", via: "get"

【问题讨论】:

  • smtp_settings 设置?
  • @Nithin 拍摄。我现在正在学习 Rails。我不知道这个=[

标签: ruby-on-rails actionmailer


【解决方案1】:

我刚刚从以前的项目中复制了我的代码

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

  config.action_mailer.delivery_method = :smtp
  ActionMailer::Base.smtp_settings = {
    address:              'smtp.gmail.com',
    port:                 587,
    domain:               'gmail.com',
    user_name:            'mailme@gmail.com',
    password:             'pwd',
    authentication:       'plain',
    enable_starttls_auto: true
  }

退房。 http://guides.rubyonrails.org/action_mailer_basics.html

【讨论】:

  • 感谢您的帮助!我试过这个但是我得到了这个错误:Net::SMTPAuthenticationError in HomeController#send_mail 534-5.7.9 Application-specific password required
  • 这是一个常见问题,有研究吗?我曾经不得不更改密码。
  • 我四处询问,是因为这个support.google.com/accounts/answer/185833?hl=en
  • 只需使用 gmail 凭据就可以了,如果您有上述问题,请将其更改为新的 1,请使用浏览器。
猜你喜欢
  • 2014-12-31
  • 2018-05-10
  • 1970-01-01
  • 2013-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-31
  • 1970-01-01
相关资源
最近更新 更多