Devise Mail is not being catched in development environment - ruby-on-rails

I have tried doing authentication using devise in my rails app, I have made use of the 'confirmable' module in devise. However I am able to sign up but i am not seeing any email captured on my mailcatcher user interface. How do I get this problem sorted???
My development.rb is configured as follows
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { :host => 'localhost: 3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {:address => 'localhost', :port => 1025}
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end

You can use Google Mail as your smtp server.
Replace
config.action_mailer.smtp_settings = {:address => 'localhost', :port => 1025}
With
ActionMailer::Base.smtp_settings = {
:address => 'smtp.gmail.com',
:domain => 'mail.google.com',
:port => 587,
:user_name => 'your#gmail.com',
:password => 'password',
:authentication => :plain,
:enable_starttls_auto => true
}

For me I used the following configuration
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => "your_gmail",
:password => "your_password",
:authentication => "plain",
:enable_starttls_auto => true
}
Then I opened my email and opened this https://www.google.com/settings/security/lesssecureapps then set it to on.
Remember also to restart your server after editing your development.rb

Related

config.action_mailer.asset_host not serving images from cloud front CDN

I have a CloudFront CDN serving my rails assets. When viewing source of assets served through a web browser it points to my CDN properly. However, Action Mailer is not using this path when serving its assets.
Why might this be?
Here is my environments/production.rb file:
config.action_mailer.perform_caching = false
config.action_mailer.default_url_options = { host: 'localhost' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.smtp_settings = {
:address => "email-smtp.us-east-1.amazonaws.com",
:port => 587,
:user_name => Figaro.env.smtp_username, #Your SMTP user
:password => Figaro.env.smtp_password, #Your SMTP password
:authentication => :login,
:enable_starttls_auto => true
}
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
config.action_controller.asset_host = Figaro.env.cloudfront_endpoint
config.action_mailer.asset_host = Figaro.env.cloudfront_endpoint
It seems you are not setting the correct value for config.action_mailer.default_url_options.
This is what the docs says:
Unlike controllers, the mailer instance doesn't have any context about the incoming request so you'll need to provide the :host parameter yourself.
As the :host usually is consistent across the application you can configure it globally in config/application.rb
it should be:
config.action_mailer.default_url_options = { host: Figaro.env.cloudfront_endpoint }
Note: make sure you are using image_url instead of image_path in your mail views/templates

Require support in ruby on rails smtp delivery method

Im trying to send a notification email to my account in gmail by using smtp delivery method when i click the place order button but i am getting all sorts of connection and authentication errors
like these:An existing connection was forcibly closed by the remote host. - SSL_connect
Net::ReadTimeout when calling ActionMailer
rails email error - 530-5.5.1 Authentication Required.
SSL_connect SYSCALL returned=5 errno=0 state=SSLv3 read server session ticket A
i have searched everywhere and everytime i try to change the port or do anything to my developments.rb file either of these errors shows up
this is my development.rb file
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports.
config.consider_all_requests_local = true
# Enable/disable caching. By default caching is disabled.
if Rails.root.join('tmp/caching-dev.txt').exist?
config.action_controller.perform_caching = true
config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=172800'
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_caching = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Suppress logger output for asset requests.
config.assets.quiet = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.perform_deliveries=true
config.action_mailer.raise_delivery_errors=true
config.action_mailer.delivery_method= :smtp
config.action_mailer.smtp_settings={
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => ENV["GMAIL_USERNAME"] ,#your gmail id
:password => ENV["GMAIL_PASSWORD"], #your gmail password
:authentication => :plain,
:enable_starttls_auto => true,
tls: true
}
end
i dont know what the hell is going on i need some help in this and currently i am getting the first error that existing connection one

Error sending emails with Rails 4 & Devise (connection refused, port 25)

I'be been having some massive issues getting emails to send. I've tried multiple ways of doing things; using gmail, mailgun, sendgrid, the mailgun gem etc, no luck at all. For some reason it's trying to send using port 25 although, as you can see below, I'm specifying port 587. The error I get is:
Errno::ECONNREFUSED (Connection refused - connect(2) for "localhost" port 25):
My development.rb file is as follows:
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
:address => 'smtp.mailgun.org',
:port => 587,
:api_key => 'key-5d321b99f722e71f759993ee41512b99',
:user_name => 'postmaster#sandbox3ed8de9510c845c68bf0d867a8f25394.mailgun.org',
:password => '(mailgun password)',
:domain => 'sandbox3ed8de9510c845c68bf0d867a8f25394.mailgun.org',
:authentication => :plain,
:enable_starttls_auto => true
}
I have looked around for solutions however none seem to solve the issue. I'm totally out of ideas.
entire Development.rb document:
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = false
config.action_controller.perform_caching = false
# Don't care if the mailer can't send.
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
user_name: "chris.edhogben#gmail.com",
password: "<password>",
authentication: 'plain',
enable_starttls_auto: true
}
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
end
Try This configuration
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'localhost',
port: 25,
domain: 'exmaple.com',
enable_starttls_auto: false
}
Use the below settigns in production.rb
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
ActionMailer::Base.smtp_settings = {
:address => 'smtp.mailgun.org',
:port => 587,
:user_name => 'postmaster#sandbox3ed8de9510c845c68bf0d867a8f25394.mailgun.org',
:password => '(mailgun password)',
:domain => 'sandbox3ed8de9510c845c68bf0d867a8f25394.mailgun.org',
:authentication => :plain
}
Use the below settigns for gmail:
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
user_name: "username",
password: "password",
authentication: 'plain',
enable_starttls_auto: true
}
If you get SMTP authentication error , then click on http://www.google.com/accounts/DisplayUnlockCaptcha & enable it. It will enable google for registering new apps within 10 minutes
add same mail configuration in production.rb also.
Restart the server and check

I don't get confirm mail

I have a problem with devise mail confirm.
I adding mailcatcher, that work correct:
Thu, 24 Sep 2015 05:49:50 +0300
From: please-change-me-at-config-initializers-devise#example.com
Reply-To: please-change-me-at-config-initializers-devise#example.com
To: ...#gmail.com
Message-ID: <560364ce3f3d_34372357331e9383d#gerdon-MS-7346.mail>
Subject: Confirmation instructions
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<p>Welcome ...#gmail.com!</p>
<p>You can confirm your account email through the link below:</p>
<p>Confirm my account</p>
but i not getting this at my gmail.
Here is my code on rails:
/development.rb
Rails.application.configure do
config.cache_classes = false
config.eager_load = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_deliveries = true
config.active_support.deprecation = :log
config.active_record.migration_error = :page_load
config.assets.debug = true
config.assets.digest = true
config.assets.raise_runtime_errors = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {:address => "localhost", :port => 1025}
end
/production.rb
Rails.application.configure do
config.log_level = :debug
config.i18n.fallbacks = true
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
config.action_mailer.default_url_options = {:host => 'localhost:3000'}
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "127.0.0.1"
:port => 25,
:domain => 'localhost:3000'
}
end
i use this comment like a documentation in my try to set mail confirm:
How do I set up email confirmation with Devise?
To enable email sending, you need to do two things.
Configure your email for in config/environments/development.rb (not sure if you've already done that.
Configure your email in Devise by editing config/initializers/devise.rb. You've definitely not done that, given the "from" address visible in your log.
Step 1. Here are settings if you are sending from a gmail account. Pay attention to all the email settings, including allowing email sending in development mode and default url option. You have to change the smtp settings to reflect your account.
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Send emails in test mode
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "domain.of.sender.net",
authentication: "plain",
user_name: "your_user_name",
password: "your_password",
enable_starttls_auto: true
}
Step 2. Configure config/initializers/devise.rb to include the email that you just configured for sending.
# Use this hook to configure devise mailer, warden hooks and so forth.
# Many of these configuration options can be set straight in your model.
Devise.setup do |config|
# The secret key used by Devise. Devise uses this key to generate
# random tokens. Changing this key will render invalid all existing
# confirmation, reset password and unlock tokens in the database.
# Devise will use the `secret_key_base` on Rails 4+ applications as its `secret_key`
# by default. You can change it below and use your own secret key.
# config.secret_key = 'ewe44lwemwle66wmew4lewwew'
# ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer,
# note that it will be overwritten if you use your own mailer class
# with default "from" parameter.
config.mailer_sender = 'YOUR_EMAIL_HERE'
This may sound like a silly question, but are you running an smtp server on localhost??

PDF attachment broken on rails 3.1.6 production environment

I store a pdf document in the database and send it by email with this lines of code:+
def invoice(payment)
#payment = payment
#user = payment.subscriber or raise(ActiveRecord::RecordNotFound)
#subscription = payment.subscription or raise(ActiveRecord::RecordNotFound)
attachments[#payment.invoice_doc_name] = {
:mime_type => 'application/pdf',
:encoding => 'base64',
:content => #payment.invoice_pdf
}
mail to: #user.email
end
This works perfectly fine on my dev, test and staging environment which is on Heroku Cedar like production. The PDF is correct, I can download it in the user interface. Production configuration is:
Railsapp::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = true
# Compress JavaScripts and CSS
config.assets.compress = true
# Specify the default JavaScript compressor
config.assets.js_compressor = :uglifier
# Specifies the header that your server uses for sending files
# (comment out if your front-end server doesn't support this)
config.action_dispatch.x_sendfile_header = nil
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true
# See everything in the log (default is :info)
# config.log_level = :debug
# Use a different logger for distributed setups
config.logger = Logger.new($stdout)
# Use a different cache store in production
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
# Enable threaded mode
# config.threadsafe!
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
# Setup for production - deliveries, no errors raised
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
config.action_mailer.default_url_options = {
:host => 'www.****.com',
:protocol => 'https'
}
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:enable_startls_auto => true,
:port => 587,
:authentication => :plain,
:user_name => '***',
:password => '***'
}
end

Resources