Skip to content

Commit

Permalink
Set a name in the from email address
Browse files Browse the repository at this point in the history
We received a report that one of our email's was classified as
spam. This might be because we were formatting the `from` email header
incorrectly. RFC5322[1] suggests that emails should include a name
alongside the email address in the from header.

[1] https://www.rfc-editor.org/rfc/rfc5322#section-3.4
  • Loading branch information
chrislo committed Jul 10, 2024
1 parent da5369e commit da89506
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class ApplicationMailer < ActionMailer::Base
default from: '[email protected]'
default from: email_address_with_name('[email protected]', 'Jam')

layout 'mailer'
end
1 change: 0 additions & 1 deletion app/mailers/broadcast_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ def newsletter(user)

mail(
to: user.email,
from: email_address_with_name('[email protected]', 'Chris (jam.coop)'),
subject: 'jam.coop - Newsletter #2',
track_opens: 'true',
message_stream: 'broadcast'
Expand Down
16 changes: 16 additions & 0 deletions test/mailers/application_mailer_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

require 'test_helper'

class TestMailer < ApplicationMailer
def application_mailer_email
mail to: '[email protected]', subject: 'A test email', body: 'A test email'
end
end

class ApplicationMailerTest < ActionMailer::TestCase
test 'an application_mailer_email from has the name and email address' do
mail = TestMailer.application_mailer_email
assert_equal 'Jam <[email protected]>', mail.message.from_address.to_s
end
end

0 comments on commit da89506

Please sign in to comment.