mirror of
https://github.com/yingziwu/mastodon.git
synced 2026-02-04 03:25:14 +00:00
Move email env var reading to yml files (#35191)
This commit is contained in:
parent
2e0a00ab46
commit
48451b782d
6 changed files with 162 additions and 33 deletions
|
|
@ -35,6 +35,7 @@ require_relative '../lib/paperclip/response_with_limit_adapter'
|
|||
require_relative '../lib/terrapin/multi_pipe_extensions'
|
||||
require_relative '../lib/mastodon/middleware/public_file_server'
|
||||
require_relative '../lib/mastodon/middleware/socket_cleanup'
|
||||
require_relative '../lib/mastodon/email_configuration_helper'
|
||||
require_relative '../lib/mastodon/feature'
|
||||
require_relative '../lib/mastodon/snowflake'
|
||||
require_relative '../lib/mastodon/version'
|
||||
|
|
@ -104,6 +105,7 @@ module Mastodon
|
|||
|
||||
config.x.cache_buster = config_for(:cache_buster)
|
||||
config.x.captcha = config_for(:captcha)
|
||||
config.x.email = config_for(:email)
|
||||
config.x.mastodon = config_for(:mastodon)
|
||||
config.x.omniauth = config_for(:omniauth)
|
||||
config.x.translation = config_for(:translation)
|
||||
|
|
|
|||
21
config/email.yml
Normal file
21
config/email.yml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# Note that these settings only apply in `production` even when other
|
||||
# keys are added here.
|
||||
production:
|
||||
delivery_method: <%= ENV.fetch('SMTP_DELIVERY_METHOD', 'smtp') %>
|
||||
from_address: <%= ENV.fetch('SMTP_FROM_ADDRESS', 'notifications@localhost') %>
|
||||
reply_to: <%= ENV.fetch('SMTP_REPLY_TO', nil) %>
|
||||
return_path: <%= ENV.fetch('SMTP_RETURN_PATH', nil) %>
|
||||
smtp_settings:
|
||||
port: <%= ENV.fetch('SMTP_PORT', nil) %>
|
||||
address: <%= ENV.fetch('SMTP_SERVER', nil) %>
|
||||
user_name: <%= ENV.fetch('SMTP_LOGIN', nil) %>
|
||||
password: <%= ENV.fetch('SMTP_PASSWORD', nil) %>
|
||||
domain: <%= ENV.fetch('SMTP_DOMAIN', ENV.fetch('LOCAL_DOMAIN', nil)) %>
|
||||
authentication: <%= ENV.fetch('SMTP_AUTH_METHOD', 'plain') %>
|
||||
ca_file: <%= ENV.fetch('SMTP_CA_FILE', '/etc/ssl/certs/ca-certificates.crt') %>
|
||||
openssl_verify_mode: <%= ENV.fetch('SMTP_OPENSSL_VERIFY_MODE', nil) %>
|
||||
enable_starttls: <%= ENV.fetch('SMTP_ENABLE_STARTTLS', nil) %>
|
||||
enable_starttls_auto: <%= ENV.fetch('SMTP_ENABLE_STARTTLS_AUTO', true) != 'false' %>
|
||||
tls: <%= ENV.fetch('SMTP_TLS', false) == 'true' ? true : nil %>
|
||||
ssl: <%= ENV.fetch('SMTP_SSL', false) == 'true' ? true : nil %>
|
||||
read_timeout: 20
|
||||
|
|
@ -99,7 +99,7 @@ Rails.application.configure do
|
|||
config.action_mailer.perform_caching = false
|
||||
|
||||
# E-mails
|
||||
outgoing_email_address = ENV.fetch('SMTP_FROM_ADDRESS', 'notifications@localhost')
|
||||
outgoing_email_address = config.x.email.from_address
|
||||
outgoing_email_domain = Mail::Address.new(outgoing_email_address).domain
|
||||
|
||||
config.action_mailer.default_options = {
|
||||
|
|
@ -107,40 +107,12 @@ Rails.application.configure do
|
|||
message_id: -> { "<#{Mail.random_tag}@#{outgoing_email_domain}>" },
|
||||
}
|
||||
|
||||
config.action_mailer.default_options[:reply_to] = ENV['SMTP_REPLY_TO'] if ENV['SMTP_REPLY_TO'].present?
|
||||
config.action_mailer.default_options[:return_path] = ENV['SMTP_RETURN_PATH'] if ENV['SMTP_RETURN_PATH'].present?
|
||||
config.action_mailer.default_options[:reply_to] = config.x.email.reply_to if config.x.email.reply_to.present?
|
||||
config.action_mailer.default_options[:return_path] = config.x.email.return_path if config.x.email.return_path.present?
|
||||
|
||||
enable_starttls = nil
|
||||
enable_starttls_auto = nil
|
||||
config.action_mailer.smtp_settings = Mastodon::EmailConfigurationHelper.smtp_settings(config.x.email.smtp_settings)
|
||||
|
||||
case ENV.fetch('SMTP_ENABLE_STARTTLS', nil)
|
||||
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.fetch('SMTP_PORT', nil),
|
||||
address: ENV.fetch('SMTP_SERVER', nil),
|
||||
user_name: ENV['SMTP_LOGIN'].presence,
|
||||
password: ENV['SMTP_PASSWORD'].presence,
|
||||
domain: ENV['SMTP_DOMAIN'] || ENV.fetch('LOCAL_DOMAIN', nil),
|
||||
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.fetch('SMTP_OPENSSL_VERIFY_MODE', nil),
|
||||
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', 'smtp').to_sym
|
||||
config.action_mailer.delivery_method = config.x.email.delivery_method.to_sym
|
||||
|
||||
config.action_dispatch.default_headers = {
|
||||
'Server' => 'Mastodon',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue