Skip to content

Commit

Permalink
feat: support for additional SMTP client options
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcooke committed Mar 4, 2024
1 parent 9dd00f6 commit 0daa667
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
15 changes: 11 additions & 4 deletions config/initializers/smtp.rb
Expand Up @@ -2,10 +2,17 @@

require "postal/config"

config = Postal::Config.smtp

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: Postal::Config.smtp.host,
user_name: Postal::Config.smtp.username,
password: Postal::Config.smtp.password,
port: Postal::Config.smtp.port
address: config.host,
user_name: config.username,
password: config.password,
port: config.port,
authentication: config.authentication_type&.to_sym,
enable_starttls: config.enable_starttls?,
enable_starttls_auto: config.enable_starttls_auto?,
openssl_verify_mode: config.openssl_verify_mode,
ssl: config.ssl?
}
5 changes: 5 additions & 0 deletions doc/config/environment-variables.md
Expand Up @@ -70,6 +70,11 @@ This document contains all the environment variables which are available for thi
| `SMTP_PORT` | Integer | The port number to send application-level e-mails to | 25 |
| `SMTP_USERNAME` | String | The username to use when authentication to the SMTP server | |
| `SMTP_PASSWORD` | String | The password to use when authentication to the SMTP server | |
| `SMTP_AUTHENTICATION_TYPE` | String | The type of authentication to use | login |
| `SMTP_ENABLE_STARTTLS` | Boolean | Use STARTTLS when connecting to the SMTP server and fail if unsupported | false |
| `SMTP_ENABLE_STARTTLS_AUTO` | Boolean | Detects if STARTTLS is enabled in the SMTP server and starts to use it | true |
| `SMTP_OPENSSL_VERIFY_MODE` | String | When using TLS, you can set how OpenSSL checks the certificate. Use 'none' for no certificate checking | peer |
| `SMTP_SSL` | Boolean | Use an SSL/TLS connection to the SMTP server (SMTPS) | false |
| `SMTP_FROM_NAME` | String | The name to use as the from name outgoing emails from Postal | Postal |
| `SMTP_FROM_ADDRESS` | String | The e-mail to use as the from address outgoing emails from Postal | postal@example.com |
| `RAILS_ENVIRONMENT` | String | The Rails environment to run the application in | production |
Expand Down
10 changes: 10 additions & 0 deletions doc/config/yaml.yml
Expand Up @@ -153,6 +153,16 @@ smtp:
username:
# The password to use when authentication to the SMTP server
password:
# The type of authentication to use
authentication_type: login
# Use STARTTLS when connecting to the SMTP server and fail if unsupported
enable_starttls: false
# Detects if STARTTLS is enabled in the SMTP server and starts to use it
enable_starttls_auto: true
# When using TLS, you can set how OpenSSL checks the certificate. Use 'none' for no certificate checking
openssl_verify_mode: peer
# Use an SSL/TLS connection to the SMTP server (SMTPS)
ssl: false
# The name to use as the from name outgoing emails from Postal
from_name: Postal
# The e-mail to use as the from address outgoing emails from Postal
Expand Down
25 changes: 25 additions & 0 deletions lib/postal/config_schema.rb
Expand Up @@ -360,6 +360,31 @@ module Postal
description "The password to use when authentication to the SMTP server"
end

string :authentication_type do
description "The type of authentication to use"
default "login"
end

boolean :enable_starttls do
description "Use STARTTLS when connecting to the SMTP server and fail if unsupported"
default false
end

boolean :enable_starttls_auto do
description "Detects if STARTTLS is enabled in the SMTP server and starts to use it"
default true
end

string :openssl_verify_mode do
description "When using TLS, you can set how OpenSSL checks the certificate. Use 'none' for no certificate checking"
default "peer"
end

boolean :ssl do
description "Use an SSL/TLS connection to the SMTP server (SMTPS)"
default false
end

string :from_name do
description "The name to use as the from name outgoing emails from Postal"
default "Postal"
Expand Down

0 comments on commit 0daa667

Please sign in to comment.