Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smtp config: support additional ssl related keys #1149

Merged
merged 2 commits into from Dec 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 8 additions & 6 deletions config/initializers/action_mailer.rb
Expand Up @@ -2,12 +2,14 @@
if Errbit::Config.email_delivery_method == :smtp
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: Errbit::Config.smtp_address,
port: Errbit::Config.smtp_port,
authentication: Errbit::Config.smtp_authentication,
user_name: Errbit::Config.smtp_user_name,
password: Errbit::Config.smtp_password,
domain: Errbit::Config.smtp_domain
address: Errbit::Config.smtp_address,
port: Errbit::Config.smtp_port,
authentication: Errbit::Config.smtp_authentication,
user_name: Errbit::Config.smtp_user_name,
password: Errbit::Config.smtp_password,
domain: Errbit::Config.smtp_domain,
enable_starttls_auto: Errbit::Config.smtp_enable_starttls_auto,
openssl_verify_mode: Errbit::Config.smtp_openssl_verify_mode
}
end

Expand Down
2 changes: 2 additions & 0 deletions config/load.rb
Expand Up @@ -53,6 +53,8 @@
smtp_address: ['SMTP_SERVER'],
smtp_port: ['SMTP_PORT'],
smtp_authentication: ['SMTP_AUTHENTICATION'],
smtp_enable_starttls_auto: ['SMTP_ENABLE_STARTTLS_AUTO'],
smtp_openssl_verify_mode: ['SMTP_OPENSSL_VERIFY_MODE'],
smtp_user_name: %w(SMTP_USERNAME SENDGRID_USERNAME),
smtp_password: %w(SMTP_PASSWORD SENDGRID_PASSWORD),
smtp_domain: ['SMTP_DOMAIN', 'SENDGRID_DOMAIN', lambda do |values|
Expand Down
4 changes: 4 additions & 0 deletions docs/configuration.md
Expand Up @@ -103,6 +103,10 @@ In order of precedence Errbit uses:
<dd>Password for SMTP auth, you could also set SENDGRID_PASSWORD
<dt>SMTP_DOMAIN
<dd>HELO domain to set for outgoing SMTP messages, you can also use SENDGRID_DOMAIN
<dt>SMTP_ENABLE_STARTTLS_AUTO
<dd>Detects if STARTTLS is enabled in your SMTP server and starts to use it
<dt>SMTP_OPENSSL_VERIFY_MODE
<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').
<dt>SENDMAIL_LOCATION
<dd>Path to sendmail
<dt>SENDMAIL_ARGUMENTS
Expand Down
16 changes: 10 additions & 6 deletions spec/initializers/action_mailer_spec.rb
Expand Up @@ -32,15 +32,19 @@ def load_initializer
allow(Errbit::Config).to receive(:smtp_user_name).and_return('my-username')
allow(Errbit::Config).to receive(:smtp_password).and_return('my-password')
allow(Errbit::Config).to receive(:smtp_domain).and_return('someotherdomain.com')
allow(Errbit::Config).to receive(:smtp_enable_starttls_auto).and_return(true)
allow(Errbit::Config).to receive(:smtp_openssl_verify_mode).and_return('peer')
load_initializer

expect(ActionMailer::Base.smtp_settings).to eq(
address: 'smtp.somedomain.com',
port: 998,
authentication: :login,
user_name: 'my-username',
password: 'my-password',
domain: 'someotherdomain.com'
address: 'smtp.somedomain.com',
port: 998,
authentication: :login,
user_name: 'my-username',
password: 'my-password',
domain: 'someotherdomain.com',
enable_starttls_auto: true,
openssl_verify_mode: 'peer'
)
end
end
Expand Down