邮件程序不发送电子邮件rails 4

时间:2014-11-18 08:37:16

标签: ruby-on-rails actionmailer

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

当我转到网址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

配置/环境/ 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"

1 个答案:

答案 0 :(得分: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