开发者

Mail not actually being sent though my log says it is

Rails 2.3.5

This is on my local.

I have a simple model / view/ controller

#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

The log says its going out.. i can do it in my console and it says its going out. But nothing actually is received in my inbox. What am I missing?

Update

Here is my 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"
}

The Create Log

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 marl开发者_运维百科ey
</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]

update:

Tried using the gmail tls plugin but it didn't work. tried moving the settings around to environment.rb to development.rb .

I am using spree, but if I put something in environment or development.rb in /config it overrides Spree's defaults. Alternatively, I can create the mail server from within Spree's admin, and with the right specs, it still doesn't budge.


If you are running your application in develop mode your email will not be sent but logged. To actually send an email in develop mode change config/environment.rb to something like:

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


In config\environments\development.rb do you still have the following lines:

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

If so, comment those, and add the following lines to enable deliveries from development:

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


I found two items that solved this piece for me.

  1. I was using Spree, so that I meant I had to configure the mail settings internally. Before I realized that I had gone with @lbz's request to install a plugin for TLS in Gmail sendings. It turns out, that that silently conflicted with the settings, so when I uninstalled it, it worked.

  2. To get emails to be sent on your testing server, you must also comment this line :

    # config.action_mailer.delivery_method = :test

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜