Skip to content

Commit 2d4ccc5

Browse files
mattscilipotistevecrozz
authored andcommitted
smtp config: support additional ssl related keys (errbit#1149)
* smtp config: support additional ssl related keys * smtp_enable_starttls_auto, smtp_openssl_verify_mode * smtp config: updated config docs with new settings * docs for SMTP_ENABLE_STARTTLS_AUTO, SMTP_OPENSSL_VERIFY_MODE
1 parent 8c01f94 commit 2d4ccc5

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

config/initializers/action_mailer.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
if Errbit::Config.email_delivery_method == :smtp
33
ActionMailer::Base.delivery_method = :smtp
44
ActionMailer::Base.smtp_settings = {
5-
address: Errbit::Config.smtp_address,
6-
port: Errbit::Config.smtp_port,
7-
authentication: Errbit::Config.smtp_authentication,
8-
user_name: Errbit::Config.smtp_user_name,
9-
password: Errbit::Config.smtp_password,
10-
domain: Errbit::Config.smtp_domain
5+
address: Errbit::Config.smtp_address,
6+
port: Errbit::Config.smtp_port,
7+
authentication: Errbit::Config.smtp_authentication,
8+
user_name: Errbit::Config.smtp_user_name,
9+
password: Errbit::Config.smtp_password,
10+
domain: Errbit::Config.smtp_domain,
11+
enable_starttls_auto: Errbit::Config.smtp_enable_starttls_auto,
12+
openssl_verify_mode: Errbit::Config.smtp_openssl_verify_mode
1113
}
1214
end
1315

config/load.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
smtp_address: ['SMTP_SERVER'],
5454
smtp_port: ['SMTP_PORT'],
5555
smtp_authentication: ['SMTP_AUTHENTICATION'],
56+
smtp_enable_starttls_auto: ['SMTP_ENABLE_STARTTLS_AUTO'],
57+
smtp_openssl_verify_mode: ['SMTP_OPENSSL_VERIFY_MODE'],
5658
smtp_user_name: %w(SMTP_USERNAME SENDGRID_USERNAME),
5759
smtp_password: %w(SMTP_PASSWORD SENDGRID_PASSWORD),
5860
smtp_domain: ['SMTP_DOMAIN', 'SENDGRID_DOMAIN', lambda do |values|

docs/configuration.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ In order of precedence Errbit uses:
103103
<dd>Password for SMTP auth, you could also set SENDGRID_PASSWORD
104104
<dt>SMTP_DOMAIN
105105
<dd>HELO domain to set for outgoing SMTP messages, you can also use SENDGRID_DOMAIN
106+
<dt>SMTP_ENABLE_STARTTLS_AUTO
107+
<dd>Detects if STARTTLS is enabled in your SMTP server and starts to use it
108+
<dt>SMTP_OPENSSL_VERIFY_MODE
109+
<dd>When using TLS, you can set how OpenSSL checks the certificate. This is really useful if you need to validate a self-signed and/or a wildcard certificate. You can use the name of an OpenSSL verify constant ('none', 'peer', 'client_once', 'fail_if_no_peer_cert').
106110
<dt>SENDMAIL_LOCATION
107111
<dd>Path to sendmail
108112
<dt>SENDMAIL_ARGUMENTS

spec/initializers/action_mailer_spec.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,19 @@ def load_initializer
3232
allow(Errbit::Config).to receive(:smtp_user_name).and_return('my-username')
3333
allow(Errbit::Config).to receive(:smtp_password).and_return('my-password')
3434
allow(Errbit::Config).to receive(:smtp_domain).and_return('someotherdomain.com')
35+
allow(Errbit::Config).to receive(:smtp_enable_starttls_auto).and_return(true)
36+
allow(Errbit::Config).to receive(:smtp_openssl_verify_mode).and_return('peer')
3537
load_initializer
3638

3739
expect(ActionMailer::Base.smtp_settings).to eq(
38-
address: 'smtp.somedomain.com',
39-
port: 998,
40-
authentication: :login,
41-
user_name: 'my-username',
42-
password: 'my-password',
43-
domain: 'someotherdomain.com'
40+
address: 'smtp.somedomain.com',
41+
port: 998,
42+
authentication: :login,
43+
user_name: 'my-username',
44+
password: 'my-password',
45+
domain: 'someotherdomain.com',
46+
enable_starttls_auto: true,
47+
openssl_verify_mode: 'peer'
4448
)
4549
end
4650
end

0 commit comments

Comments
 (0)