Class: PostmailRuby::Configuration
- Inherits:
-
Object
- Object
- PostmailRuby::Configuration
- Defined in:
- lib/postmail_ruby/configuration.rb
Overview
Configuration holds all settings loaded from environment variables or via configuration block. It provides helpers to build SMTP settings and determine if default Rails SMTP configuration should be disabled.
Instance Attribute Summary collapse
-
#api_endpoint ⇒ Object
API endpoint for HTTP delivery.
-
#api_key ⇒ Object
API key for HTTP delivery (used in X-Server-API-Key header).
-
#delivery_method ⇒ Object
Delivery method to use (:smtp or :api).
-
#smtp_authentication ⇒ Object
SMTP authentication type (:plain, :login, etc.).
-
#smtp_domain ⇒ Object
Domain used for SMTP.
-
#smtp_enable_starttls_auto ⇒ Object
Enable STARTTLS for SMTP (boolean).
-
#smtp_host ⇒ Object
SMTP host.
-
#smtp_password ⇒ Object
SMTP password.
-
#smtp_port ⇒ Object
SMTP port (integer).
-
#smtp_ssl ⇒ Object
Use SSL/TLS implicit connection for SMTP (boolean).
-
#smtp_username ⇒ Object
SMTP username.
Instance Method Summary collapse
-
#disable_default_smtp? ⇒ Boolean
Returns true if the default Rails SMTP configuration should be disabled.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#smtp_settings ⇒ Object
Compose SMTP settings hash suitable for Mail::SMTP or ActionMailer.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/postmail_ruby/configuration.rb', line 33 def initialize # set defaults from environment variables @delivery_method = (ENV['POSTMAIL_DELIVERY_METHOD'] || 'smtp').downcase.to_sym @disable_default_smtp = truthy?(ENV['POSTMAIL_DISABLE_RAILS_SMTP']) @api_endpoint = ENV['POSTMAIL_API_ENDPOINT'] || 'https://postal.exanora.com/api/v1/send/message' @api_key = ENV['POSTMAIL_API_KEY'] @smtp_host = ENV['POSTMAIL_SMTP_HOST'] || 'localhost' @smtp_port = integer_or_nil(ENV['POSTMAIL_SMTP_PORT']) || 25 @smtp_username = ENV['POSTMAIL_SMTP_USERNAME'] @smtp_password = ENV['POSTMAIL_SMTP_PASSWORD'] @smtp_authentication = (ENV['POSTMAIL_SMTP_AUTH'] || 'login').downcase.to_sym @smtp_enable_starttls_auto = truthy?(ENV['POSTMAIL_SMTP_ENABLE_STARTTLS_AUTO']) # If not explicitly set, enable_starttls_auto defaults to true unless SSL is enabled @smtp_enable_starttls_auto = !truthy?(ENV['POSTMAIL_SMTP_SSL']) if @smtp_enable_starttls_auto.nil? @smtp_ssl = truthy?(ENV['POSTMAIL_SMTP_SSL']) @smtp_domain = ENV['POSTMAIL_SMTP_DOMAIN'] end |
Instance Attribute Details
#api_endpoint ⇒ Object
API endpoint for HTTP delivery
13 14 15 |
# File 'lib/postmail_ruby/configuration.rb', line 13 def api_endpoint @api_endpoint end |
#api_key ⇒ Object
API key for HTTP delivery (used in X-Server-API-Key header)
15 16 17 |
# File 'lib/postmail_ruby/configuration.rb', line 15 def api_key @api_key end |
#delivery_method ⇒ Object
Delivery method to use (:smtp or :api)
11 12 13 |
# File 'lib/postmail_ruby/configuration.rb', line 11 def delivery_method @delivery_method end |
#smtp_authentication ⇒ Object
SMTP authentication type (:plain, :login, etc.)
25 26 27 |
# File 'lib/postmail_ruby/configuration.rb', line 25 def smtp_authentication @smtp_authentication end |
#smtp_domain ⇒ Object
Domain used for SMTP
31 32 33 |
# File 'lib/postmail_ruby/configuration.rb', line 31 def smtp_domain @smtp_domain end |
#smtp_enable_starttls_auto ⇒ Object
Enable STARTTLS for SMTP (boolean)
27 28 29 |
# File 'lib/postmail_ruby/configuration.rb', line 27 def smtp_enable_starttls_auto @smtp_enable_starttls_auto end |
#smtp_host ⇒ Object
SMTP host
17 18 19 |
# File 'lib/postmail_ruby/configuration.rb', line 17 def smtp_host @smtp_host end |
#smtp_password ⇒ Object
SMTP password
23 24 25 |
# File 'lib/postmail_ruby/configuration.rb', line 23 def smtp_password @smtp_password end |
#smtp_port ⇒ Object
SMTP port (integer)
19 20 21 |
# File 'lib/postmail_ruby/configuration.rb', line 19 def smtp_port @smtp_port end |
#smtp_ssl ⇒ Object
Use SSL/TLS implicit connection for SMTP (boolean)
29 30 31 |
# File 'lib/postmail_ruby/configuration.rb', line 29 def smtp_ssl @smtp_ssl end |
#smtp_username ⇒ Object
SMTP username
21 22 23 |
# File 'lib/postmail_ruby/configuration.rb', line 21 def smtp_username @smtp_username end |
Instance Method Details
#disable_default_smtp? ⇒ Boolean
Returns true if the default Rails SMTP configuration should be disabled. When this is true, PostmailRuby will clear ‘config.action_mailer.smtp_settings`.
55 56 57 |
# File 'lib/postmail_ruby/configuration.rb', line 55 def disable_default_smtp? @disable_default_smtp end |
#smtp_settings ⇒ Object
Compose SMTP settings hash suitable for Mail::SMTP or ActionMailer.
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/postmail_ruby/configuration.rb', line 60 def smtp_settings settings = { address: smtp_host, port: smtp_port, user_name: smtp_username, password: smtp_password, authentication: smtp_authentication, enable_starttls_auto: smtp_enable_starttls_auto, ssl: smtp_ssl } settings[:domain] = smtp_domain if smtp_domain # Remove nil values to avoid overriding defaults settings.compact end |