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??
Related
After I configure to use postmark service to post emails I'm facing some troubles with development and staging envs.
Short explanation: portmark is working nice in the below situations with 'ok', and when there is DeserializationError it seems that the active job is failing because it is looking to see if the user id exists on production database.
Development env:
devise mailing -> ActiveJob::DeserializationError
deliver_later -> ActiveJob::DeserializationError
delover_now -> ok
Staging env
devise mailing -> ActiveJob::DeserializationError
deliver_later -> ActiveJob::DeserializationError
delover_now -> ok
production env
devise mailing -> ok
deliver_later -> ok
deliver_now -> ok
Long explanation:
When I'm on these two envs and requests with devise the confirmation instructions, it sends a link to this email with a production url with the token attached to it which points to wrong page.
The most intriguing thing is that after I send an email from development or staging envs console, and I opened up sidekiq dashboard and I found out that when there is no user id on production associated with the id that this email was requested to send (from the other envs), this mailing fails with this message:
Console:
> Rails.env
"development"
> #user.id
22
> UserMailer.welcome(#user).deliver_later
Sidekiq error:
ActiveJob::DeserializationError: Error while trying to deserialize
arguments: Couldn't find User with 'id'=22
Console:
> Rails.env
"staging"
> #user.id
15
> UserMailer.welcome(#user).deliver_later
Sidekiq error:
ActiveJob::DeserializationError: Error while trying to deserialize
arguments: Couldn't find User with 'id'=15
Some configs:
Rails 5.0.1
postmark (1.14.0)
postmark-rails (0.18.0)
production.rb
...
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_token => ENV["POSTMARK_API_KEY"] }
config.action_mailer.default_url_options = { host: "www.mywebsite.com" }
...
development.rb
...
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_token => ENV["POSTMARK_API_KEY"] }
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
...
staging.rb
...
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_token => ENV["POSTMARK_API_KEY"] }
config.action_mailer.default_url_options = { host: "website.herokuapp.com" }
...
sidekiq.yml
:concurrency: 3
:timeout: 60
:verbose: true
:queues:
- default
- mailers
Obs: all the three environments uses different postmark api key.
UPDATE 1
Here is the development:
development.rb
Rails.application.configure do
config.action_mailer.delivery_method = :postmark
config.action_mailer.postmark_settings = { :api_token => ENV["POSTMARK_API_KEY"] }
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.cache_classes = false
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
config.assets.precompile += %w( '.svg' )
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = true
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
end
I changed to the old configuration with gmail and the problem persists...
development.rb
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.action_mailer.delivery_method = :letter_opener
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
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
config.assets.precompile += %w( '.svg' )
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = true
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.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: 'gmail.com',
user_name: ENV['GMAIL_ADDRESS'],
password: ENV['GMAIL_APP_PASSWORD'],
authentication: "plain",
enable_starttls_auto: true
}
config.action_mailer.default_url_options = {host: "localhost:3000"}
end
UPDATE 2:
I also tried to go to past branches which the mailing was working and nothing (I restarted the server)...
This is a partial solution to make possible to use mailing on test envs in my case.
On this rails mailing documentation on topic 10.2 Deserialization says:
If a passed record is deleted after the job is enqueued but before the #perform method is called Active Job will raise an ActiveJob::DeserializationError exception.
So I realized that somehow the record has being deleted from cache before the sending method (deliver_later) takes action. If this is going only on development and staging environments, then I attached on:
production.rb
config.active_job.queue_adapter = :sidekiq
development.rb / staging.rb
config.active_job.queue_adapter = :inline
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
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
When I run my mailer in development mode, I get the following error:
Net::ReadTimeout in SchoolApplicationsController#create
Here is the controller method that is getting the timeout
def create
#school_application = SchoolApplication.new(school_application_params)
#school_application.program_cost = #school_application.calculate_cost_to_charge(params[:school_application][:program], params[:school_application][:duration])
if #school_application.save
NotificationsMailer.send_application(#school_application).deliver
redirect_to application_path(#school_application.id)
else
Rails.logger.debug(#school_application.errors.full_messages)
#school_application.errors.full_messages.each do |msg|
flash.now[:error] = msg
end
render action: "new"
end
end
I am positive the error is being caused by the NotificationsMailer call because when
I comment it out, I no longer get the error.
Here is my mailer, and the settings:
class NotificationsMailer < ActionMailer::Base
default :from => "from#slf.net"
default :to => "nayr#slf.net"
def send_application(application)
#application = application
mail(:subject => "New Application")
end
end
Here is my environments/development.rb smtp settings:
Fls::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.
# 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.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'secure3309.hostgator.com',
port: 465,
domain: 'slf.net',
ssl: true,
user_name: ENV['slf_username'],
password: ENV['slf_password'],
authentication: 'plain',
enable_starttls_auto: true }
end
When I write ENV['slf_username'] in the Rails console I get the right value. Same with the password. The username is in the format user#slf.net. Is that correct or is the right format just "user" and the domain is implied from domain parameter?
After reading this post I took another look at my smtp settings and added
tls: true
changed
port: 465 to port: '465' as I noticed that most people write it as a string. Also Similarly changed the string "plain" to the symbol :plain
I faced the similar issue when i connect the smtp mail to qq mail(business mail).
I updated my settings by following the post as like below:
config.action_mailer.smtp_settings = {
address: 'smtp.exmail.qq.com',
port: '465',
domain: 'groobusiness.com',
user_name: ENV['GMAIL_USER_NAME'],
password: ENV['GMAIL_PASSWORD'],
authentication: :plain,
enable_starttls_auto: true,
openssl_verify_mode: 'none',
ssl: true,
tls: true
}
And the issue got solved.
Hope it might be helpful for someone who is facing this issue.
add following code in intitialize
require 'net/smtp'
module Net
class SMTP
def tls?
true
end
end
end
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