Skip to content

Commit 3d1e909

Browse files
authored
Add extended SMTP config options (#386)
1 parent 9263651 commit 3d1e909

File tree

4 files changed

+59
-4
lines changed

4 files changed

+59
-4
lines changed

config/environments/development.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,23 @@
4343
user_name: Settings.mail.smtp_user_name,
4444
password: Settings.mail.smtp_password,
4545
authentication: Settings.mail.smtp_authentication,
46-
enable_starttls_auto: Settings.mail.smtp_starttls,
46+
enable_starttls_auto: Settings.mail.smtp_enable_starttls_auto,
4747
open_timeout: Settings.mail.smtp_open_timeout,
4848
read_timeout: Settings.mail.smtp_read_timeout
4949
}
5050

51+
if Settings.mail.smtp_domain
52+
config.action_mailer.smtp_settings[:domain] = Settings.mail.smtp_domain
53+
end
54+
55+
if Settings.mail.smtp_openssl_verify_mode
56+
config.action_mailer.smtp_settings[:openssl_verify_mode] = Settings.mail.smtp_openssl_verify_mode.to_sym
57+
end
58+
59+
if Settings.mail.smtp_enable_starttls
60+
config.action_mailer.smtp_settings[:enable_starttls] = Settings.mail.smtp_enable_starttls
61+
end
62+
5163
# Print deprecation notices to the Rails logger.
5264
config.active_support.deprecation = :log
5365

config/environments/private.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,20 @@
2929
user_name: Settings.mail.smtp_user_name,
3030
password: Settings.mail.smtp_password,
3131
authentication: Settings.mail.smtp_authentication,
32-
enable_starttls_auto: Settings.mail.smtp_starttls,
32+
enable_starttls_auto: Settings.mail.smtp_enable_starttls_auto,
3333
open_timeout: Settings.mail.smtp_open_timeout,
3434
read_timeout: Settings.mail.smtp_read_timeout
3535
}
36+
37+
if Settings.mail.smtp_domain
38+
config.action_mailer.smtp_settings[:domain] = Settings.mail.smtp_domain
39+
end
40+
41+
if Settings.mail.smtp_openssl_verify_mode
42+
config.action_mailer.smtp_settings[:openssl_verify_mode] = Settings.mail.smtp_openssl_verify_mode.to_sym
43+
end
44+
45+
if Settings.mail.smtp_enable_starttls
46+
config.action_mailer.smtp_settings[:enable_starttls] = Settings.mail.smtp_enable_starttls
47+
end
3648
end

config/environments/production.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,23 @@
8080
user_name: Settings.mail.smtp_user_name,
8181
password: Settings.mail.smtp_password,
8282
authentication: Settings.mail.smtp_authentication,
83-
enable_starttls_auto: Settings.mail.smtp_starttls,
83+
enable_starttls_auto: Settings.mail.smtp_enable_starttls_auto,
8484
open_timeout: Settings.mail.smtp_open_timeout,
8585
read_timeout: Settings.mail.smtp_read_timeout
8686
}
8787

88+
if Settings.mail.smtp_domain
89+
config.action_mailer.smtp_settings[:domain] = Settings.mail.smtp_domain
90+
end
91+
92+
if Settings.mail.smtp_openssl_verify_mode
93+
config.action_mailer.smtp_settings[:openssl_verify_mode] = Settings.mail.smtp_openssl_verify_mode.to_sym
94+
end
95+
96+
if Settings.mail.smtp_enable_starttls
97+
config.action_mailer.smtp_settings[:enable_starttls] = Settings.mail.smtp_enable_starttls
98+
end
99+
88100
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
89101
# the I18n.default_locale when a translation cannot be found).
90102
config.i18n.fallbacks = true

config/settings.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ throttling:
185185
# for things such as forgot password, unlock account, confirm account etc.
186186
# If `enable_logins` is set to true above, the following _are required_ to be
187187
# filled out with valid values.
188+
#
189+
# These values are passed through to ActionMailer configuration. The documentation
190+
# for ActionMailer is at:
191+
# https://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration
192+
#
188193
mail:
189194
# Email delivery errors will be shown in the application
190195
# Environment Variable Override: PWP__MAIL__RAISE_DELIVERY_ERRORS='false'
@@ -202,6 +207,10 @@ mail:
202207
# Environment Variable Override: PWP__MAIL__SMTP_PASSWORD='something@&#$'
203208
# smtp_password: ''
204209

210+
# If you need to specify a HELO domain, you can do it here.
211+
# Environment Variable Override: PWP__MAIL__SMTP_DOMAIN='xyz.dev'
212+
# smtp_domain: ''
213+
205214
# Port of the SMTP server
206215
# Environment Variable Override: PWP__MAIL__SMTP_PORT='587'
207216
smtp_port: 587
@@ -217,7 +226,11 @@ mail:
217226

218227
# Use STARTTLS when connecting to your SMTP server and fail if unsupported.
219228
# Environment Variable Override: PWP__MAIL__SMTP_STARTTLS='true'
220-
smtp_starttls: true
229+
# smtp_starttls: false
230+
231+
# Detects if STARTTLS is enabled in your SMTP server and starts to use it. Defaults to true.
232+
# Environment Variable Override: PWP__MAIL__SMTP_ENABLE_STARTTLS_AUTO='false'
233+
smtp_enable_starttls_auto: true
221234

222235
# Number of seconds to wait while attempting to open a connection.
223236
# Environment Variable Override: PWP__MAIL__SMTP_OPEN_TIMEOUT='10'
@@ -227,6 +240,12 @@ mail:
227240
# Environment Variable Override: PWP__MAIL__SMTP_READ_TIMEOUT='10'
228241
smtp_read_timeout: 10
229242

243+
# When using TLS, you can set how OpenSSL checks the certificate. This is
244+
# useful if you need to validate a self-signed and/or a wildcard certificate.
245+
# This can be one of the OpenSSL verify constants, :none or :peer
246+
# Environment Variable Override: PWP__MAIL__SMTP_OPENSSL_VERIFY_MODE='none'
247+
# smtp_openssl_verify_mode: 'peer'
248+
230249
# Configure the e-mail address which will be shown as 'From' in emails
231250
# See config/initializers/devise.rb where this is used
232251
# Environment Variable Override: PWP__MAIL__MAILER_SENDER='"Password Pusher" <[email protected]>'

0 commit comments

Comments
 (0)