邮件实际上并没有通过我的日志发送它说是

时间:2010-11-28 19:55:14

标签: ruby-on-rails email actionmailer

Rails 2.3.5

这是在我当地的。

我有一个简单的模型/视图/控制器

#contact.rb

def deliver_contact
  ContactMailer.deliver_contact(self)
end

#contacts_controller

def create
  @contact = Contact.new(params[:contact])

  respond_to do |wants|
    if @contact.save
      @contact.deliver_contact
      #flash[:notice] = 'Contact was successfully created.'
      wants.html { redirect_to('/thanks') }
    else
      wants.html { render :action => "new" }
    end
  end

日志说它出去了..我可以在我的控制台上做它并且它说出去了。但我的收件箱中实际上没有收到任何内容。我错过了什么?

更新

这是我的development.rb

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
  :address => "smtp.gmail.com",
  :port => '25',
  :domain => "website.com",
  :authentication => :login,
  :user_name => "snackmail@gmail.com",
  :password => "aged-cheese"
}

创建日志

Processing ContactsController#create (for 127.0.0.1 at 2010-11-28 16:12:49) [POST]
  Parameters: {"commit"=>"PUNCH IT, CHEWY!", "action"=>"create", "authenticity_token"=>"3zayXGIOWeNLwb+jhx5cIxWgHqEJdv6iwj6I=", "contact"=>{"name"=>"bob marley", "message"=>"asdfasdf", "state_id"=>"Regarding an existing order", "email"=>"daniel@gmail.com"}, "controller"=>"contacts"}
Cache miss: Spree::Config ({})
  Preference Load (0.3ms)   SELECT * FROM "preferences" WHERE ("preferences".owner_id = 1 AND "preferences".owner_type = 'Configuration') 
  Configuration Load (0.1ms)   SELECT * FROM "configurations" WHERE ("configurations"."id" = 1) 
  CACHE (0.0ms)   SELECT * FROM "configurations" WHERE ("configurations"."id" = 1) 
Cache write (will save 2.65ms): Spree::Config
  Contact Create (0.8ms)   INSERT INTO "contacts" ("name", "city", "zip", "created_at", "optin", "updated_at", "state_id", "message", "email") VALUES('bob marley', NULL, NULL, '2010-11-28 21:12:49', NULL, '2010-11-28 21:12:49', 'Regarding an existing order', 'asdfasdf', 'daniel.levine4@gmail.com')
Sent mail to daniel@gmail.com

Date: Sun, 28 Nov 2010 16:12:50 -0500
From: info@jersey.com
To: daniel@gmail.com
Subject: HOLY !@ you got mail!
Mime-Version: 1.0
Content-Type: text/html; charset=utf-8

<strong>You have just received a dank crispy email.</strong>
<br />
<p>
  Here are the details of the message:
</p>
<p>
  <strong>Name:</strong>
  bob marley
</p>
<p>
  <strong>Email:</strong>
  daniel@gmail.com
</p>

<p>
  <strong>Subject:</strong>
  Regarding an existing order
</p>

<p>
  <strong>Message:</strong>
  <br />
  asdfasdf
</p>
Redirected to http://localhost:3000/thanks
Completed in 893ms (DB: 5) | 302 Found [http://localhost/contacts]

更新

尝试使用gmail tls插件,但它不起作用。尝试将设置移动到environment.rb到development.rb。

我正在使用狂欢,但如果我在环境中放置一些东西或在/ config中放置development.rb它会覆盖Spree的默认值。或者,我可以在Spree的管理员中创建邮件服务器,并且使用正确的规范,它仍然没有让步。

3 个答案:

答案 0 :(得分:6)

如果您在开发模式下运行应用程序,您的电子邮件将不会被发送但会被记录。要在开发模式下实际发送电子邮件,请将config/environment.rb更改为:

Rails::Initializer.run do |config|
  ...
  config.action_mailer.delivery_method = :sendmail # add this line
end

答案 1 :(得分:1)

config\environments\development.rb中你还有以下几行:

# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false

如果是,请评论这些,并添加以下行 从开发中获得交付:

# To test if we can actually send mails!
config.action_mailer.raise_delivery_errors = true # for test
config.action_mailer.perform_deliveries = true

答案 2 :(得分:0)

我发现有两件物品可以解决这件事。

  1. 我使用的是Spree,所以我的意思是我必须在内部配置邮件设置。在我意识到我已经和@lbz请求在Gmail发送中安装TLS插件之前。事实证明,这与设置无声地冲突,因此当我卸载它时,它起作用了。

  2. 要在测试服务器上发送电子邮件,您还必须对此行发表评论:

    # config.action_mailer.delivery_method = :test