Skip to content

Commit 2d1fa1e

Browse files
committed
Extract settings for system email addresses
1 parent 6ce115d commit 2d1fa1e

File tree

9 files changed

+33
-12
lines changed

9 files changed

+33
-12
lines changed

app/mailers/application_mailer.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@
33
class ApplicationMailer < ActionMailer::Base
44
prepend_view_path "app/views/emails"
55

6-
SUPPORT_EMAIL = "[email protected]"
6+
FROM_ADDRESS = Rails.configuration.settings.emails.transactional_from_address
7+
FROM_NAME = Rails.configuration.settings.emails.transactional_from_name
78

8-
default from: email_address_with_name(SUPPORT_EMAIL, "Joy of Rails")
9+
default from: email_address_with_name(FROM_ADDRESS, FROM_NAME)
910
layout "emails/mailer"
1011

12+
def self.test_recipient_email
13+
Rails.configuration.settings.emails.test_recipient
14+
end
15+
1116
def support_email
12-
email_address_with_name(SUPPORT_EMAIL, "Joy of Rails")
17+
email_address_with_name(FROM_ADDRESS, FROM_NAME)
1318
end
1419

1520
helper_method :support_email

config/application.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,10 @@ class Application < Rails::Application
5454

5555
# Set up solid cable options
5656
config.solid_cable = ActiveSupport::OrderedOptions.new
57+
58+
# Set up custom settings
59+
config.settings = ActiveSupport::OrderedOptions.new
60+
61+
config.settings.postmark_api_token = Rails.application.credentials.postmark&.api_token || "POSTMARK_API_TEST"
5762
end
5863
end

config/credentials/production.yml.enc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
DWCnTuYrtpM13SLH4cdvHIU7k3/QoN+sSgNwU07E9WzX9eJCvR3DxQS5fjYMZ9ibKemWXTO2kElpMHm8xQaz6/lcBn80lKJHeEpKrqfsRDgoZ+6cgIPYn+nuDF1bpHRVk0BX1fTlOnQFrZQw8boXgh1+1C4GlXFwLUVL11ZR34vJbl2++p4EBxFeUE90WhWeLR9uDXwtLS70xPKQlVIyAWHCcw+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dQ39je8YvcYQkL3mlSRr0PKznCuDZmmv5MB4S0krGj/58wMv7a2yeeWcHDtL2XvdFvvXP8d3QRHXJZBCdEs2W/RqIso1Is7owLczLpnWMsKVEBxgXdpLQIEGRGFZDKqEF9DUrYxI0Oi75ZV48Jt19pKYH9aDtDlVqUX1H0NgLgMERLNV3R+5aEq831x1xgnNsIcs0a9iGBycbSar+WDfax3L4yu02n423lA2ygS4JfP78Byl02NuyTJ5w4AXZNhYKXobWjhF69bUX0tq91oiEEvFhN28Z8zLar8ETCf7zlHRjbW+nr5x0v60a17BfTg5cp+UBpD5HJsn23PNdD4bjKtL39EW0PwQgDvhWiuMxz0Ato3W9jZ1QAhxHtpzhQ4ZZ6vDCtvc1v2Lh0JO0pXZMSTm5Th33Gd7/yDelftmzahCq84jKTn2qTJOrPFZHHBbrWC3nIv/GAtcnp44aeXLZWCVsJHXUXbhhXq1HxluBPmFovmRZmDByX0MdeQxyMo5k++b+lGsILeash2RmRAlfh3L9gS+S7Yq4lt83ebRqKPfowEmoPlobbqtcovHOz3mrQZah5tyzt76BFZgQBS8tlXTTKik0enT6jADTU0VkwXv53Lb9XC4elGIGh+UU8HmbLw2ugFzmVANKWRTOdx3CvF/WQrpcbn2Eko1cIAT1HmXDWvOp9bZDJLEpct6IoSko3W9bCghDM/cKhouF+vi0ZPJAR8K0w2mXTWdTe8sTZmk13cg4SstYg30Ze3qRWmN5L96GbemAv0Hm1PJDVlTUSYH9FC7LVX7eclqY/P7LN/r6C3T4nukcQ8fs9G9VEns3yVzm8ZrF+BSaMWrr2YX+FZu+u7467Rg5I+9a+VikquXu+djTAmIxfcS40+71TsgghFzgh4=--/VUcntmltCA2Muwe--N0iiWNQQiAHAxcq82fSbGw==

config/environments/production.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777

7878
# Configure Postmark
7979
config.action_mailer.delivery_method = :postmark
80-
config.action_mailer.postmark_settings = {api_token: Rails.application.credentials.postmark&.api_token || "POSTMARK_API_TEST"}
80+
config.action_mailer.postmark_settings = {api_token: config.settings.postmark_api_token}
8181

8282
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
8383
# the I18n.default_locale when a translation cannot be found).

config/initializers/emails.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Rails.application.configure do
2+
config.settings.emails = ActiveSupport::OrderedOptions.new
3+
4+
emails = Rails.application.credentials.emails
5+
6+
config.settings.emails.transactional_from_address = emails&.transactional_from_address || "[email protected]"
7+
config.settings.emails.transactional_from_name = emails&.transactional_from_name || "Joy of Rails"
8+
config.settings.emails.broadcast_from_address = emails&.broadcast_from_address || "[email protected]"
9+
config.settings.emails.broadcast_from_name = emails&.broadcast_from_name || "Joy of Rails"
10+
config.settings.emails.test_recipient = emails&.test_recipient || "[email protected]"
11+
end

spec/mailers/emails/admin_user_mailer_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
it "renders the headers" do
1010
expect(mail.subject).to eq("New Joy of Rails User")
1111
expect(mail.to).to eq(["[email protected]"])
12-
expect(mail.from).to eq(["hello@joyofrails.com"])
12+
expect(mail.from).to eq(["hello@example.com"])
1313
end
1414

1515
it "renders the body" do

spec/mailers/emails/heartbeat_mailer_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
end
1212

1313
# Test the body of the sent email contains what we expect it to
14-
expect(email.from).to eq ["hello@joyofrails.com"]
14+
expect(email.from).to eq ["hello@example.com"]
1515
expect(email.to).to eq ["[email protected]"]
1616
expect(email.subject).to eq "It’s alive!"
1717
expect(email.body.encoded).to match("The Joy of Rails email integration is working!")

spec/mailers/emails/magic_session_mailer_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
it "renders the headers" do
99
expect(mail.subject).to eq("Your sign-in link")
1010
expect(mail.to).to eq(["[email protected]"])
11-
expect(mail.from).to eq(["hello@joyofrails.com"])
11+
expect(mail.from).to eq(["hello@example.com"])
1212
end
1313

1414
it "renders the body" do
@@ -23,7 +23,7 @@
2323
it "renders the headers" do
2424
expect(mail.subject).to eq("No account found")
2525
expect(mail.to).to eq(["[email protected]"])
26-
expect(mail.from).to eq(["hello@joyofrails.com"])
26+
expect(mail.from).to eq(["hello@example.com"])
2727
end
2828

2929
it "renders the body" do

spec/mailers/emails/user_mailer_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
it "renders the headers" do
99
expect(mail.subject).to eq("Confirm your email address")
1010
expect(mail.to).to eq(["[email protected]"])
11-
expect(mail.from).to eq(["hello@joyofrails.com"])
11+
expect(mail.from).to eq(["hello@example.com"])
1212
end
1313

1414
it "renders the body" do
@@ -23,7 +23,7 @@
2323
it "renders the headers" do
2424
expect(mail.subject).to eq("Reset your password")
2525
expect(mail.to).to eq(["[email protected]"])
26-
expect(mail.from).to eq(["hello@joyofrails.com"])
26+
expect(mail.from).to eq(["hello@example.com"])
2727
end
2828

2929
it "renders the body" do
@@ -38,7 +38,7 @@
3838
it "renders the headers" do
3939
expect(mail.subject).to eq("Welcome to Joy of Rails!")
4040
expect(mail.to).to eq(["[email protected]"])
41-
expect(mail.from).to eq(["hello@joyofrails.com"])
41+
expect(mail.from).to eq(["hello@example.com"])
4242
end
4343

4444
it "renders the body" do

0 commit comments

Comments
 (0)