Reputation: 1611
I finally have email confirmations being sent out properly on development (using Devise for authentication, etc.) but on production I simply cannot get it to work.
UPDATE/EDIT #1:
After trying out the suggestion below which unfortunately did not solve the problem, I then modified my production settings as follows:
UPDATE/EDIT #2:
Tried to modify the :domain
value:
Rails.application.routes.default_url_options[:host] = 'obscure-crag-6843.herokuapp.com'
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
:address => 'smtp.sengrid.net',
:port => 587,
:authentication => 'plain',
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'obscure-crag-6843.heroku.com',
:enable_starttls_auto => true
}
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
Still getting errors:
2015-02-02T16:52:39.634893+00:00 app[web.1]: Processing by Devise::ConfirmationsController#create as HTML
2015-02-02T16:52:39.624339+00:00 app[web.1]: Started POST "/users/confirmation" for 66.108.200.119 at 2015-02-02 16:52:39 +0000
2015-02-02T16:52:39.634923+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"3yPKp3FqN2Mfxg+s28xQDpLhWtkLRFt1ZxfygyM5JNKCGlo1+nsx0dXy0NbSt7D80TvKIuPfSESziGQ/L9HoiQ==", "user"=>{"email"=>"[email protected]"}, "c
ommit"=>"Resend confirmation instructions"}
2015-02-02T16:52:39.673202+00:00 app[web.1]: User Load (12.2ms) SELECT "users".* FROM "users" WHERE "users"."email" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["email", "[email protected]"]]
2015-02-02T16:52:39.673202+00:00 app[web.1]: User Load (12.2ms) SELECT "users".* FROM "users" WHERE "users"."email" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["email", "[email protected]"]]
2015-02-02T16:52:39.928958+00:00 app[web.1]: User Load (3.5ms) SELECT "users".* FROM "users" WHERE "users"."confirmation_token" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["confirmation_token", "d00c657be3922503cb350e6db9e5b20ac6daa2
a8aa401fb346d504d0e2d89f2e"]]
2015-02-02T16:52:39.941419+00:00 app[web.1]: SQL (3.2ms) UPDATE "users" SET "confirmation_token" = $1, "confirmation_sent_at" = $2, "updated_at" = $3 WHERE "users"."id" = $4 [["confirmation_token", "d00c657be3922503cb350e6db9e5b20ac
6daa2a8aa401fb346d504d0e2d89f2e"], ["confirmation_sent_at", "2015-02-02 16:52:39.929928"], ["updated_at", "2015-02-02 16:52:39.933892"], ["id", 1]]
2015-02-02T16:52:40.047348+00:00 app[web.1]: Rendered devise/mailer/confirmation_instructions.html.erb (7.5ms)
2015-02-02T16:52:39.933525+00:00 app[web.1]: (3.2ms) BEGIN
2015-02-02T16:52:39.949859+00:00 app[web.1]: (7.8ms) COMMIT
2015-02-02T16:52:40.300090+00:00 app[web.1]: Devise::Mailer#confirmation_instructions: processed outbound mail in 347.2ms
2015-02-02T16:52:40.300084+00:00 app[web.1]:
2015-02-02T16:53:09.608907+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/users/confirmation" host=obscure-crag-6843.herokuapp.com request_id=88102416-e8e8-4e2d-904e-61505b7cc80d fwd="66.108.200.119" d
yno=web.1 connect=2ms service=30001ms status=503 bytes=0
2015-02-02T16:53:10.591515+00:00 app[web.1]: From: [email protected]
2015-02-02T16:53:10.591525+00:00 app[web.1]: Mime-Version: 1.0
2015-02-02T16:53:10.591522+00:00 app[web.1]: Message-ID: <54cfab584a63e_33f8391b77e986273@5849319e-9d85-442b-b13b-b79cd9373d33.mail>
2015-02-02T16:53:10.591526+00:00 app[web.1]: Content-Type: text/html;
2015-02-02T16:53:10.539928+00:00 app[web.1]: Sent mail to [email protected] (30239.5ms)
2015-02-02T16:53:10.591510+00:00 app[web.1]: Date: Mon, 02 Feb 2015 16:52:40 +0000
2015-02-02T16:53:10.591520+00:00 app[web.1]: To: [email protected]
2015-02-02T16:53:10.539921+00:00 app[web.1]:
2015-02-02T16:53:10.591518+00:00 app[web.1]: Reply-To: [email protected]
2015-02-02T16:53:10.591532+00:00 app[web.1]: <p>Welcome [email protected]!</p>
2015-02-02T16:53:10.591528+00:00 app[web.1]: charset=UTF-8
2015-02-02T16:53:10.591523+00:00 app[web.1]: Subject: Confirmation instructions
2015-02-02T16:53:10.591528+00:00 app[web.1]: charset=UTF-8 [115/1420]
2015-02-02T16:53:10.591523+00:00 app[web.1]: Subject: Confirmation instructions
2015-02-02T16:53:10.591529+00:00 app[web.1]: Content-Transfer-Encoding: 7bit
2015-02-02T16:53:10.591912+00:00 app[web.1]: Completed 500 Internal Server Error in 30957ms
2015-02-02T16:53:10.591534+00:00 app[web.1]: <p>You can confirm your account email through the link below:</p>
2015-02-02T16:53:10.591535+00:00 app[web.1]:
2015-02-02T16:53:10.591537+00:00 app[web.1]: <p><a href="http://obscure-crag-6843.herokuapp.com/users/confirmation?confirmation_token=c9agbLB_yT57z4shtjZP">Confirm my account</a></p>
2015-02-02T16:53:10.591530+00:00 app[web.1]:
2015-02-02T16:53:10.591533+00:00 app[web.1]:
2015-02-02T16:53:10.591538+00:00 app[web.1]:
2015-02-02T16:53:10.630637+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:520:in `start'
2015-02-02T16:53:10.630628+00:00 app[web.1]: Net::OpenTimeout (execution expired):
2015-02-02T16:53:10.630630+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:541:in `initialize'
2015-02-02T16:53:10.630631+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:541:in `open'
2015-02-02T16:53:10.630633+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:541:in `tcp_socket'
2015-02-02T16:53:10.630634+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:551:in `block in do_start'
2015-02-02T16:53:10.630635+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/net/smtp.rb:550:in `do_start'
2015-02-02T16:53:10.630623+00:00 app[web.1]:
2015-02-02T16:53:10.630645+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.2.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
At this point I'm either going to to try to use a different mail provider or just go back to Gmail for the time being, though of course I'll have to deal with this down the road eventually. If anyone has any more suggestions that would be great.
Upvotes: 0
Views: 585
Reputation: 36
I also had problems sending emails in production (devise, heroku) but I was able to solve it. Comparing my code settings to yours I found these lines different:
Rails.application.routes.default_url_options[:host] = 'obscure-crag-6843.herokuapp.com'
:domain => 'obscure-crag-6843.heroku.com',
:address => 'smtp.sengrid.net',
in
Rails.application.configure do
I have
config.action_mailer.default_url_options = { host: 'myappname.herokuapp.com' }
and in
config.action_mailer.smtp_settings
everything is the same except
:address => 'smtp.sendgrid.net', (you misspelled sendgrid)
:domain => 'heroku.com',
You need to add-on Sendgrid to Heroku of course. Hope this helps!
Upvotes: 1
Reputation: 79
I noticed that you are using a :domain attribute in your code. Although I have never used one before, could you try changing the domain to your app-name.heroku.com instead of heorku.com? I will show you how I use mailing code for myself:
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["gmail_username"],
password: ENV["gmail_password"]
}
Good luck :)
Upvotes: 0