Skip to content

Instantly share code, notes, and snippets.

@ahmad19
Last active February 9, 2021 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmad19/829cba9311aadea5124ab3b101239a79 to your computer and use it in GitHub Desktop.
Save ahmad19/829cba9311aadea5124ab3b101239a79 to your computer and use it in GitHub Desktop.
Steps to allow email sending on heroku through sidekiq.
# Create Procfile which is required by heroku.
web: bin/rails server -p $PORT
worker: bundle exec sidekiq -c 2 -e staging
# REDIS
# REDISTOGO_URL for local is bydefault: redis://0.0.0.0:6379/0
# REDISTOGO_URL for heroku
# Use Redistogo heroku addon
# Addon will provide REDISTOGO_URL which should be added in the heroku config.
# config/initializers/sidekiq.rb
Sidekiq.configure_server do |config|
config.redis = { url: ENV["REDISTOGO_URL"], id: nil }
end
Sidekiq.configure_client do |config|
config.redis = { url: ENV["REDISTOGO_URL"], id: nil }
end
# smtp settings:
# https://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration-for-gmail
# make sure domain name does not contain https.
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: ENV['DOMAIN'],
user_name: ENV['GMAIL_USERNAME'],
password: ENV['GMAIL_PASSWORD'],
authentication: 'plain',
enable_starttls_auto: true }
config.action_mailer.default_url_options = { :host => ENV['DOMAIN'] }
# And since we are using gmail therefore google blocks the application to connect with gmail. Therefore we need to allow that connection.
# Reference is here - https://stackoverflow.com/a/20262500/1468122
# Sidekiq docs from wiki
# Heroku - https://github.com/mperham/sidekiq/wiki/Heroku
# Redis - https://github.com/mperham/sidekiq/wiki/Using-Redis#multiple-redis-instances
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment