Skip to content

Commit 83c6a2c

Browse files
authored
Merge pull request huginn#3418 from huginn/default_smtp_settings
Change the default SMTP settings
2 parents 9898736 + 4d6f910 commit 83c6a2c

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

.env.example

+8-5
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,25 @@ IMPORT_DEFAULT_SCENARIO_FOR_ALL_USERS=true
102102
# SMTP_AUTHENTICATION to login and the SMTP_PORT to 465.
103103
#
104104
# If you use a local SMTP server without authentication such as Postfix,
105-
# SMTP_USER_NAME must be set to none or else you will receive
106-
# errors that AUTH not enabled.
105+
# set SMTP_AUTHENTICATON to `none`.
107106

108107
# Uncomment if you want to use `/usr/sbin/sendmail` to send email instead of SMTP.
109108
# This option is ignored unless RAILS_ENV=production, and setting it to `sendmail` causes the settings in the rest of this section (except EMAIL_FROM_ADDRESS) to be ignored.
110109
# SMTP_DELIVERY_METHOD=sendmail
111110

112111
SMTP_DOMAIN=your-domain-here.com
113-
SMTP_USER_NAME=[email protected]
114-
SMTP_PASSWORD=somepassword
115112
SMTP_SERVER=smtp.gmail.com
116113
SMTP_PORT=587
117-
SMTP_AUTHENTICATION=plain
118114
SMTP_ENABLE_STARTTLS_AUTO=true
119115
SMTP_SSL=false
120116

117+
SMTP_AUTHENTICATION=plain
118+
119+
# SMTP_PASSWORD=somepassword
120+
121+
# or without authentication:
122+
# SMTP_AUTHENTICATION=none
123+
121124
# Set to true to send real emails via SMTP when running in the development Rails environment.
122125
# Set to false to have emails intercepted in development and displayed at http://localhost:3000/letter_opener
123126
SEND_EMAIL_IN_DEVELOPMENT=false

config/initializers/action_mailer.rb

+22-15
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
ActionMailer::Base.smtp_settings = {
2-
address: ENV['SMTP_SERVER'] || "smtp.gmail.com",
3-
port: ENV['SMTP_PORT'] || 587,
4-
domain: ENV['SMTP_DOMAIN'],
5-
authentication: ENV['SMTP_AUTHENTICATION'] == 'none' ? nil : ENV['SMTP_AUTHENTICATION'] || "plain",
6-
enable_starttls_auto: ENV['SMTP_ENABLE_STARTTLS_AUTO'] == 'true',
7-
ssl: ENV['SMTP_SSL'] == 'true',
8-
user_name: ENV['SMTP_USER_NAME'] == 'none' ? nil : ENV['SMTP_USER_NAME'].presence,
9-
password: ENV['SMTP_USER_NAME'] == 'none' ? nil : ENV['SMTP_PASSWORD'].presence,
10-
openssl_verify_mode: ENV['SMTP_OPENSSL_VERIFY_MODE'].presence,
11-
ca_path: ENV['SMTP_OPENSSL_CA_PATH'].presence,
12-
ca_file: ENV['SMTP_OPENSSL_CA_FILE'].presence,
13-
read_timeout: ENV['SMTP_READ_TIMEOUT']&.to_i,
14-
open_timeout: ENV['SMTP_OPEN_TIMEOUT']&.to_i,
15-
}
1+
ActionMailer::Base.smtp_settings = {}.tap { |config|
2+
config[:address] = ENV['SMTP_SERVER'] || 'smtp.gmail.com'
3+
config[:port] = ENV['SMTP_PORT']&.to_i || 587
4+
config[:domain] = ENV['SMTP_DOMAIN']
5+
6+
authentication = ENV['SMTP_AUTHENTICATION'].presence || 'plain'
7+
user_name = ENV['SMTP_USER_NAME'].presence || 'none'
8+
9+
if authentication != 'none' && user_name != 'none'
10+
config[:authentication] = authentication
11+
config[:user_name] = user_name
12+
config[:password] = ENV['SMTP_PASSWORD'].presence
13+
end
14+
15+
config[:enable_starttls_auto] = ENV['SMTP_ENABLE_STARTTLS_AUTO'] == 'true'
16+
config[:ssl] = ENV['SMTP_SSL'] == 'true'
17+
config[:openssl_verify_mode] = ENV['SMTP_OPENSSL_VERIFY_MODE'].presence
18+
config[:ca_path] = ENV['SMTP_OPENSSL_CA_PATH'].presence
19+
config[:ca_file] = ENV['SMTP_OPENSSL_CA_FILE'].presence
20+
config[:read_timeout] = ENV['SMTP_READ_TIMEOUT']&.to_i
21+
config[:open_timeout] = ENV['SMTP_OPEN_TIMEOUT']&.to_i
22+
}

0 commit comments

Comments
 (0)