Skip to content

Commit 99bee0e

Browse files
Make SMTP config conditional on SMTP_ADDRESS
- If `SMTP_ADDRESS` is set, configure Action Mailer to use it, along with additional optional SMTP-related settings. - Otherwise, don't set config (for compatibility with engines like fizzy-saas). - Remove sendmail env setup, since by default there is no sendmail in the container, and custom deployment can use whatever config the want directly. If we end up needing this, we can bring it back via its own env.
1 parent 9de59ca commit 99bee0e

3 files changed

Lines changed: 19 additions & 35 deletions

File tree

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This repo contains a starter deployment file that you can modify for your own sp
1414
The steps to configure your very own Fizzy are:
1515

1616
1. Fork the repo
17-
2. Edit few things in config/deploy.yml, .kamal/secrets, and config/environments/production.rb
17+
2. Edit few things in config/deploy.yml and .kamal/secrets
1818
3. Run `kamal setup` to do your first deploy.
1919

2020
We'll go through each of these in turn.
@@ -37,6 +37,7 @@ We've added comments to that file to highlight what each setting needs to be, bu
3737
- `ssh/user`: If you access your server a `root` you can leave this alone; if you use a different user, set it here.
3838
- `proxy/ssl` and `proxy/host`: Kamal can set up SSL certificates for you automatically. To enable that, set the hostname again as `host`. If you don't want SSL for some reason, you can set `ssl: false` to turn it off.
3939
- `env/clear/MAILER_FROM_ADDRESS`: This is the email address that Fizzy will send emails from. It should usually be an address from the same domain where you're running Fizzy.
40+
- `env/clear/SMTP_ADDRESS`: The address of an SMTP server that you can send email through. You can use a 3rd-party service for this, like Sendgrid or Postmark, in which case their documentation will tell you what to use for this.
4041

4142
Fizzy also requires a few environment variables to be set up, some of which contain secrets.
4243
The simplest way to do this is to put them in a file called `.kamal/secrets`.
@@ -58,6 +59,7 @@ SMTP_PASSWORD=email-provider-password
5859
The values you enter here will be specific to you, and you can get or create them as follows:
5960

6061
- `SECRET_KEY_BASE` should be a long, random secret. You can run `bin/rails secret` to create a suitable value for this.
62+
- `SMTP_USERNAME` & `SMTP_PASSWORD` should be valid credentials for your SMTP server. If you're using a 3rd-party service here, consult their documentation for what to use.
6163
- `VAPID_PUBLIC_KEY` & `VAPID_PRIVATE_KEY` are a pair of credentials that are used for sending notifications. You can create your own keys by starting a development console with:
6264

6365
```sh
@@ -73,10 +75,6 @@ The values you enter here will be specific to you, and you can get or create the
7375
puts "VAPID_PUBLIC_KEY=#{vapid_key.public_key}"
7476
```
7577

76-
- `SMTP_USERNAME`/`SMTP_PASSWORD` are credentials you should get from your email provider.
77-
78-
Lastly, you'll need to set up the rest of your email configuration in `config/environments/production.rb`. There is an example configuration in comments at the top of that file. The actual settings you use here will depend on your email provider, but in most cases will look similar to that section, so you can uncomment it and edit to suit. Note that it will use the `SMTP_USERNAME` and `SMTP_PASSWORD` values you entered in your secrets.
79-
8078
Once you've made all those changes, commit them to your fork so they're saved.
8179

8280
### Deploy Fizzy!

config/deploy.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ env:
2828
- SMTP_USERNAME
2929
- SMTP_PASSWORD
3030
clear:
31-
MAILER_FROM_ADDRESS: support@example.com # The email address that Fizzy sends email from
31+
MAILER_FROM_ADDRESS: support@example.com # The email "from" address that Fizzy sends email from
32+
SMTP_ADDRESS: mail.example.com # The SMTP server you'll use to send email
3233
SOLID_QUEUE_IN_PUMA: true # Run background jobs in the app container
3334

3435

config/environments/production.rb

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@
55

66
# Email provider Settings
77
#
8-
# Configure these according to whichever email provider you use. An example setup
9-
# using SMTP looks like the following:
10-
#
11-
# config.action_mailer.smtp_settings = {
12-
# address: 'smtp.example.com', # The address of your email provider's SMTP server
13-
# port: 2525,
14-
# domain: 'example.com', # Your domain, which Fizzy will send email from
15-
# user_name: ENV["SMTP_USERNAME"],
16-
# password: ENV["SMTP_PASSWORD"],
17-
# authentication: :plain,
18-
# enable_starttls_auto: true
19-
# }
8+
# SMTP setting can be configured via environment variables.
9+
# For other configuration options, consult the Action Mailer documentation.
10+
if smtp_address = ENV["SMTP_ADDRESS"].presence
11+
config.action_mailer.delivery_method = :smtp
12+
config.action_mailer.smtp_settings = {
13+
address: smtp_address,
14+
port: ENV.fetch("SMTP_PORT", "587").to_i,
15+
domain: ENV.fetch("SMTP_DOMAIN", nil),
16+
user_name: ENV.fetch("SMTP_USERNAME", nil),
17+
password: ENV.fetch("SMTP_PASSWORD", nil),
18+
authentication: ENV.fetch("SMTP_AUTHENTICATION", "plain"),
19+
enable_starttls_auto: ENV.fetch("SMTP_ENABLE_STARTTLS_AUTO", "true") == "true"
20+
}
21+
end
2022

2123
# Code is not reloaded between requests.
2224
config.enable_reloading = false
@@ -80,23 +82,6 @@
8082

8183
config.action_mailer.perform_caching = false
8284

83-
config.action_mailer.delivery_method = ENV.fetch("MAILER_DELIVERY_METHOD", "smtp").to_sym
84-
85-
config.action_mailer.smtp_settings = {
86-
address: ENV.fetch("SMTP_ADDRESS", "localhost"),
87-
port: ENV.fetch("SMTP_PORT", "587").to_i,
88-
domain: ENV.fetch("SMTP_DOMAIN", nil),
89-
user_name: ENV.fetch("SMTP_USERNAME", nil),
90-
password: ENV.fetch("SMTP_PASSWORD", nil),
91-
authentication: ENV.fetch("SMTP_AUTHENTICATION", "plain"),
92-
enable_starttls_auto: ENV.fetch("SMTP_ENABLE_STARTTLS_AUTO", "true") == "true"
93-
}
94-
95-
config.action_mailer.sendmail_settings = {
96-
location: ENV.fetch("SENDMAIL_LOCATION", "/usr/sbin/sendmail"),
97-
arguments: ENV.fetch("SENDMAIL_ARGUMENTS", "-i")
98-
}
99-
10085
# Ignore bad email addresses and do not raise email delivery errors.
10186
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
10287
# config.action_mailer.raise_delivery_errors = false

0 commit comments

Comments
 (0)