chore: Make SMTP environment variables configurable (#1868)
fixes: #1647
This commit is contained in:
@@ -34,40 +34,6 @@ Rails.application.configure do
|
||||
|
||||
config.active_job.queue_adapter = :sidekiq
|
||||
|
||||
# Email related config
|
||||
config.action_mailer.perform_caching = false
|
||||
config.action_mailer.perform_deliveries = true
|
||||
config.action_mailer.raise_delivery_errors = true
|
||||
config.action_mailer.default_url_options = { host: ENV['FRONTEND_URL'] }
|
||||
|
||||
smtp_settings = {
|
||||
port: ENV['SMTP_PORT'] || 25,
|
||||
domain: ENV['SMTP_DOMAIN'] || 'localhost',
|
||||
address: ENV['SMTP_ADDRESS'] || 'chatwoot.com'
|
||||
}
|
||||
|
||||
if ENV['SMTP_AUTHENTICATION'].present?
|
||||
smtp_settings[:user_name] = ENV['SMTP_USERNAME']
|
||||
smtp_settings[:password] = ENV['SMTP_PASSWORD']
|
||||
smtp_settings[:authentication] = ENV['SMTP_AUTHENTICATION']
|
||||
smtp_settings[:enable_starttls_auto] = ENV['SMTP_ENABLE_STARTTLS_AUTO'] if ENV['SMTP_ENABLE_STARTTLS_AUTO'].present?
|
||||
end
|
||||
|
||||
if ENV['LETTER_OPENER']
|
||||
config.action_mailer.delivery_method = :letter_opener
|
||||
else
|
||||
config.action_mailer.delivery_method = :smtp
|
||||
config.action_mailer.smtp_settings = smtp_settings
|
||||
end
|
||||
|
||||
# Set this to appropriate ingress service for which the options are :
|
||||
# :relay for Exim, Postfix, Qmail
|
||||
# :mailgun for Mailgun
|
||||
# :mandrill for Mandrill
|
||||
# :postmark for Postmark
|
||||
# :sendgrid for Sendgrid
|
||||
config.action_mailbox.ingress = ENV.fetch('RAILS_INBOUND_EMAIL_SERVICE', 'relay').to_sym
|
||||
|
||||
Rails.application.routes.default_url_options = { host: ENV['FRONTEND_URL'] }
|
||||
|
||||
# Print deprecation notices to the Rails logger.
|
||||
|
||||
@@ -76,7 +76,7 @@ Rails.application.configure do
|
||||
# Use a different logger for distributed setups.
|
||||
# require 'syslog/logger'
|
||||
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
|
||||
|
||||
|
||||
if ActiveModel::Type::Boolean.new.cast(ENV.fetch('RAILS_LOG_TO_STDOUT', true))
|
||||
logger = ActiveSupport::Logger.new($stdout)
|
||||
logger.formatter = config.log_formatter
|
||||
@@ -98,17 +98,6 @@ Rails.application.configure do
|
||||
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
|
||||
# config.action_mailer.raise_delivery_errors = false
|
||||
|
||||
# Chatwoot production settings
|
||||
config.action_mailer.default_url_options = { host: ENV['FRONTEND_URL'] }
|
||||
config.action_mailer.smtp_settings = {
|
||||
address: ENV['SMTP_ADDRESS'],
|
||||
port: ENV['SMTP_PORT'] || 587,
|
||||
user_name: ENV['SMTP_USERNAME'],
|
||||
password: ENV['SMTP_PASSWORD'],
|
||||
authentication: :login,
|
||||
enable_starttls_auto: true
|
||||
}
|
||||
|
||||
# Set this to appropriate ingress service for which the options are :
|
||||
# :relay for Exim, Postfix, Qmail
|
||||
# :mailgun for Mailgun
|
||||
|
||||
@@ -54,31 +54,9 @@ Rails.application.configure do
|
||||
# Use a real queuing backend for Active Job (and separate queues per environment)
|
||||
# config.active_job.queue_adapter = :resque
|
||||
# config.active_job.queue_name_prefix = "chatwoot_#{Rails.env}"
|
||||
config.action_mailer.perform_caching = false
|
||||
config.action_mailer.default_url_options = { host: ENV['FRONTEND_URL'] }
|
||||
config.action_mailer.smtp_settings = {
|
||||
address: ENV['SMTP_ADDRESS'],
|
||||
port: 587,
|
||||
user_name: ENV['SMTP_USERNAME'], # Your SMTP user
|
||||
password: ENV['SMTP_PASSWORD'], # Your SMTP password
|
||||
authentication: :login,
|
||||
enable_starttls_auto: true
|
||||
}
|
||||
|
||||
Rails.application.routes.default_url_options = { host: ENV['FRONTEND_URL'] }
|
||||
|
||||
# Ignore bad email addresses and do not raise email delivery errors.
|
||||
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
|
||||
# config.action_mailer.raise_delivery_errors = false
|
||||
|
||||
# Set this to appropriate ingress service for which the options are :
|
||||
# :relay for Exim, Postfix, Qmail
|
||||
# :mailgun for Mailgun
|
||||
# :mandrill for Mandrill
|
||||
# :postmark for Postmark
|
||||
# :sendgrid for Sendgrid
|
||||
config.action_mailbox.ingress = ENV.fetch('RAILS_INBOUND_EMAIL_SERVICE', 'relay').to_sym
|
||||
|
||||
# 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 = [I18n.default_locale]
|
||||
|
||||
@@ -12,7 +12,7 @@ Devise.setup do |config|
|
||||
# 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 = ENV.fetch('MAILER_SENDER_EMAIL', 'accounts@chatwoot.com')
|
||||
config.mailer_sender = ENV.fetch('MAILER_SENDER_EMAIL', 'Chatwoot <accounts@chatwoot.com>')
|
||||
|
||||
# Configure the class responsible to send e-mails.
|
||||
# config.mailer = 'Devise::Mailer'
|
||||
|
||||
45
config/initializers/mailer.rb
Normal file
45
config/initializers/mailer.rb
Normal file
@@ -0,0 +1,45 @@
|
||||
Rails.application.configure do
|
||||
#########################################
|
||||
# Configuration Related to Action Mailer
|
||||
#########################################
|
||||
|
||||
config.action_mailer.delivery_method = :smtp
|
||||
# We need the application frontend url to be used in our emails
|
||||
config.action_mailer.default_url_options = { host: ENV['FRONTEND_URL'] } if ENV['FRONTEND_URL'].present?
|
||||
# We load certain mailer templates from our database. This ensures changes to it is reflected immediately
|
||||
config.action_mailer.perform_caching = false
|
||||
config.action_mailer.perform_deliveries = true
|
||||
config.action_mailer.raise_delivery_errors = true
|
||||
|
||||
# Config related to smtp
|
||||
smtp_settings = {
|
||||
domain: ENV.fetch('SMTP_DOMAIN', ''),
|
||||
address: ENV.fetch('SMTP_ADDRESS', 'localhost'),
|
||||
port: ENV.fetch('SMTP_PORT', 587)
|
||||
}
|
||||
|
||||
smtp_settings[:authentication] = ENV.fetch('SMTP_AUTHENTICATION', 'login').to_sym if ENV.fetch('SMTP_AUTHENTICATION', '').present?
|
||||
smtp_settings[:user_name] = ENV.fetch('SMTP_USERNAME', '')
|
||||
smtp_settings[:password] = ENV.fetch('SMTP_PASSWORD', '')
|
||||
smtp_settings[:enable_starttls_auto] = ActiveModel::Type::Boolean.new.cast(ENV.fetch('SMTP_ENABLE_STARTTLS_AUTO', true))
|
||||
smtp_settings[:openssl_verify_mode] = ENV.fetch('SMTP_OPENSSL_VERIFY_MODE', 'peer')
|
||||
smtp_settings[:ssl] = ActiveModel::Type::Boolean.new.cast(ENV.fetch('SMTP_SSL', true)) if ENV['SMTP_SSL']
|
||||
smtp_settings[:tls] = ActiveModel::Type::Boolean.new.cast(ENV.fetch('SMTP_TLS', true)) if ENV['SMTP_TLS']
|
||||
|
||||
config.action_mailer.delivery_method = :smtp
|
||||
config.action_mailer.smtp_settings = smtp_settings
|
||||
# You can use letter opener for your local development by setting the environment variable
|
||||
config.action_mailer.delivery_method = :letter_opener if Rails.env.development? && ENV['LETTER_OPENER']
|
||||
|
||||
#########################################
|
||||
# Configuration Related to Action MailBox
|
||||
#########################################
|
||||
|
||||
# Set this to appropriate ingress service for which the options are :
|
||||
# :relay for Exim, Postfix, Qmail
|
||||
# :mailgun for Mailgun
|
||||
# :mandrill for Mandrill
|
||||
# :postmark for Postmark
|
||||
# :sendgrid for Sendgrid
|
||||
config.action_mailbox.ingress = ENV.fetch('RAILS_INBOUND_EMAIL_SERVICE', 'relay').to_sym
|
||||
end
|
||||
Reference in New Issue
Block a user