Convert SMTP configs into environments vars (#13542)
Co-authored-by: rhymes <rhymes@hey.com>
This commit is contained in:
parent
4225819ae0
commit
25f6b3e9ed
4 changed files with 55 additions and 22 deletions
10
.env_sample
10
.env_sample
|
|
@ -155,9 +155,13 @@ STACK_EXCHANGE_APP_KEY=""
|
|||
GITHUB_KEY="Optional"
|
||||
GITHUB_SECRET="Optional"
|
||||
|
||||
# For Sendgrid email
|
||||
# https://sendgrid.com/docs/for-developers/sending-email/upgrade-your-authentication-method-to-api-keys/#upgrade-to-api-keys-for-your-smtp-integration
|
||||
SENDGRID_API_KEY="Optional, Production only"
|
||||
# For SMTP configuration
|
||||
SMTP_ADDRESS=
|
||||
SMTP_PORT=
|
||||
SMTP_DOMAIN=
|
||||
SMTP_USER_NAME=
|
||||
SMTP_PASSWORD=
|
||||
SMTP_AUTHENTICATION=
|
||||
|
||||
|
||||
# Disable simplecov coverage testing when running rspec locally
|
||||
|
|
|
|||
|
|
@ -14,8 +14,7 @@ Rails.application.configure do
|
|||
# Show full error reports.
|
||||
config.consider_all_requests_local = true
|
||||
|
||||
DEFAULT_EXPIRATION = 1.hour.to_i.freeze
|
||||
config.cache_store = :redis_cache_store, { url: ENV["REDIS_URL"], expires_in: DEFAULT_EXPIRATION }
|
||||
config.cache_store = :redis_cache_store, { url: ENV["REDIS_URL"], expires_in: 1.hour.to_i }
|
||||
|
||||
# Enable/disable caching. By default caching is disabled.
|
||||
# Run rails dev:cache to toggle caching.
|
||||
|
|
@ -90,13 +89,12 @@ Rails.application.configure do
|
|||
config.action_mailer.perform_deliveries = true
|
||||
config.action_mailer.default_url_options = { host: config.app_domain }
|
||||
config.action_mailer.smtp_settings = {
|
||||
address: "smtp.gmail.com",
|
||||
port: "587",
|
||||
enable_starttls_auto: true,
|
||||
user_name: '<%= ENV["DEVELOPMENT_EMAIL_USERNAME"] %>',
|
||||
password: '<%= ENV["DEVELOPMENT_EMAIL_PASSWORD"] %>',
|
||||
authentication: :plain,
|
||||
domain: config.app_domain
|
||||
address: ENV["SMTP_ADDRESS"],
|
||||
port: ENV["SMTP_PORT"],
|
||||
authentication: ENV["SMTP_AUTHENTICATION"].presence || :plain,
|
||||
user_name: ENV["SMTP_USER_NAME"],
|
||||
password: ENV["SMTP_PASSWORD"],
|
||||
domain: ENV["SMTP_DOMAIN"].presence || config.app_domain
|
||||
}
|
||||
|
||||
config.action_mailer.preview_path = Rails.root.join("spec/mailers/previews")
|
||||
|
|
|
|||
|
|
@ -129,15 +129,25 @@ Rails.application.configure do
|
|||
config.action_mailer.delivery_method = :smtp
|
||||
config.action_mailer.perform_deliveries = true
|
||||
config.action_mailer.default_url_options = { host: protocol + ENV["APP_DOMAIN"].to_s }
|
||||
ActionMailer::Base.smtp_settings = {
|
||||
address: "smtp.sendgrid.net",
|
||||
port: "587",
|
||||
authentication: :plain,
|
||||
user_name: "apikey",
|
||||
password: ENV["SENDGRID_API_KEY"],
|
||||
domain: ENV["APP_DOMAIN"],
|
||||
enable_starttls_auto: true
|
||||
}
|
||||
ActionMailer::Base.smtp_settings = if ENV["SENDGRID_API_KEY"].present?
|
||||
{
|
||||
address: "smtp.sendgrid.net",
|
||||
port: 587,
|
||||
authentication: :plain,
|
||||
user_name: "apikey",
|
||||
password: ENV["SENDGRID_API_KEY"],
|
||||
domain: ENV["APP_DOMAIN"]
|
||||
}
|
||||
else
|
||||
{
|
||||
address: ENV["SMTP_ADDRESS"],
|
||||
port: ENV["SMTP_PORT"],
|
||||
authentication: ENV["SMTP_AUTHENTICATION"],
|
||||
user_name: ENV["SMTP_USER_NAME"],
|
||||
password: ENV["SMTP_PASSWORD"],
|
||||
domain: ENV["SMTP_DOMAIN"]
|
||||
}
|
||||
end
|
||||
|
||||
if ENV["HEROKU_APP_URL"].present? && ENV["HEROKU_APP_URL"] != ENV["APP_DOMAIN"]
|
||||
config.middleware.use Rack::HostRedirect,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,24 @@
|
|||
title: Emails
|
||||
---
|
||||
|
||||
# Setting up email
|
||||
|
||||
If you would like to enable transactional email using services like SendGrid or
|
||||
Mailgun, you can configure it by using the following environment variables:
|
||||
|
||||
```shell
|
||||
SMTP_ADDRESS= # ie. "smtp.sendgrid.net"
|
||||
SMTP_PORT= # ie. 587
|
||||
SMTP_DOMAIN=
|
||||
SMTP_USER_NAME=
|
||||
SMTP_PASSWORD=
|
||||
SMTP_AUTHENTICATION= # defaults to :plain
|
||||
```
|
||||
|
||||
We follow the standard `ActionMailer` configuration. For more info, please check out
|
||||
Rails'
|
||||
[official documentation](https://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration).
|
||||
|
||||
# Previewing emails in development
|
||||
|
||||
You can view email previews at <http://localhost:3000/rails/mailers>.
|
||||
|
|
@ -10,4 +28,7 @@ Previews are setup in the directory `spec/mailers/previews`.
|
|||
|
||||
# Overriding mailer templates
|
||||
|
||||
To update the contents of emails that the app sends, edit the views under `app/views/mailers`. Note that this app uses the [`devise_invitable` gem](https://github.com/scambra/devise_invitable) for invitations. The views for this gem are stored under `app/views/devise/mailer`.
|
||||
To update the contents of emails that the app sends, edit the views under
|
||||
`app/views/mailers`. Note that this app uses the
|
||||
[`devise_invitable` gem](https://github.com/scambra/devise_invitable) for
|
||||
invitations. The views for this gem are stored under `app/views/devise/mailer`.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue