use .env and support SMTP configuration

This commit is contained in:
greyidol 2023-09-02 16:33:06 +00:00
parent e5b9d58b2e
commit a6e7c6582d
4 changed files with 43 additions and 2 deletions

3
.gitignore vendored
View File

@ -4,6 +4,9 @@
.byebug_history .byebug_history
/config/database.yml /config/database.yml
.env
.env.production
.env.development
/coverage /coverage

View File

@ -5,6 +5,7 @@ source "https://rubygems.org"
gem "i18n-js", "4.0" gem "i18n-js", "4.0"
gem "rails", "~> 6.1" gem "rails", "~> 6.1"
gem "rails-i18n", "~> 7.0" gem "rails-i18n", "~> 7.0"
gem "dotenv-rails", "~> 2.8"
gem "cssbundling-rails", "~> 1.2" gem "cssbundling-rails", "~> 1.2"
gem "jsbundling-rails", "~> 1.1" gem "jsbundling-rails", "~> 1.1"

View File

@ -135,6 +135,10 @@ GEM
devise (>= 4.8.0) devise (>= 4.8.0)
diff-lcs (1.5.0) diff-lcs (1.5.0)
docile (1.4.0) docile (1.4.0)
dotenv (2.8.1)
dotenv-rails (2.8.1)
dotenv (= 2.8.1)
railties (>= 3.2)
dry-core (1.0.0) dry-core (1.0.0)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
zeitwerk (~> 2.6) zeitwerk (~> 2.6)
@ -506,6 +510,7 @@ DEPENDENCIES
devise (~> 4.9) devise (~> 4.9)
devise-async devise-async
devise-i18n devise-i18n
dotenv-rails (~> 2.8)
dry-initializer (~> 3.1) dry-initializer (~> 3.1)
dry-types (~> 1.7) dry-types (~> 1.7)
factory_bot_rails factory_bot_rails

View File

@ -73,8 +73,40 @@ Rails.application.configure do
# config.active_job.queue_name_prefix = "justask_#{Rails.env}" # config.active_job.queue_name_prefix = "justask_#{Rails.env}"
config.action_mailer.perform_caching = false config.action_mailer.perform_caching = false
# Use sendmail config.action_mailer.default_options[:reply_to] = ENV['SMTP_REPLY_TO'] if ENV['SMTP_REPLY_TO'].present?
config.action_mailer.delivery_method = :sendmail config.action_mailer.default_options[:return_path] = ENV['SMTP_RETURN_PATH'] if ENV['SMTP_RETURN_PATH'].present?
enable_starttls = nil
enable_starttls_auto = nil
case ENV['SMTP_ENABLE_STARTTLS']
when 'always'
enable_starttls = true
when 'never'
enable_starttls = false
when 'auto'
enable_starttls_auto = true
else
enable_starttls_auto = ENV['SMTP_ENABLE_STARTTLS_AUTO'] != 'false'
end
config.action_mailer.smtp_settings = {
port: ENV['SMTP_PORT'],
address: ENV['SMTP_SERVER'],
user_name: ENV['SMTP_LOGIN'].presence,
password: ENV['SMTP_PASSWORD'].presence,
domain: ENV['SMTP_DOMAIN'] || ENV['LOCAL_DOMAIN'],
authentication: ENV['SMTP_AUTH_METHOD'] == 'none' ? nil : ENV['SMTP_AUTH_METHOD'] || :plain,
ca_file: ENV['SMTP_CA_FILE'].presence || '/etc/ssl/certs/ca-certificates.crt',
openssl_verify_mode: ENV['SMTP_OPENSSL_VERIFY_MODE'],
enable_starttls: enable_starttls,
enable_starttls_auto: enable_starttls_auto,
tls: ENV['SMTP_TLS'].presence && ENV['SMTP_TLS'] == 'true',
ssl: ENV['SMTP_SSL'].presence && ENV['SMTP_SSL'] == 'true',
read_timeout: 20,
}
config.action_mailer.delivery_method = ENV.fetch('SMTP_DELIVERY_METHOD', 'sendmail').to_sym
# Ignore bad email addresses and do not raise email delivery errors. # 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. # Set this to true and configure the email server for immediate delivery to raise delivery errors.