Skip to content

Commit e5481ed

Browse files
Only show SMTP-To if different from To+Cc+Bcc
Co-authored-by: Jonathan Hefner <[email protected]>
1 parent 3162afe commit e5481ed

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

railties/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* In mailer preview, only show SMTP-To if it differs from the union of To, Cc and Bcc.
2+
3+
*Christian Schmidt*
4+
15
* Enable YJIT by default on new applications running Ruby 3.3+
26

37
Adds a `config/initializers/enable_yjit.rb` initializer that enables YJIT

railties/lib/rails/templates/rails/mailers/email.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@
6161
<body>
6262
<header>
6363
<dl>
64-
<% if @email.respond_to?(:smtp_envelope_from) && Array(@email.from) != Array(@email.smtp_envelope_from) %>
64+
<% if Array(@email.from) != Array(@email.smtp_envelope_from) %>
6565
<dt>SMTP-From:</dt>
6666
<dd id="smtp_from"><%= @email.smtp_envelope_from %></dd>
6767
<% end %>
6868

69-
<% if @email.respond_to?(:smtp_envelope_to) && @email.to != @email.smtp_envelope_to %>
69+
<% if Set[*@email.to, *@email.cc, *@email.bcc] != Set[*@email.smtp_envelope_to] %>
7070
<dt>SMTP-To:</dt>
71-
<dd id="smtp_to"><%= @email.smtp_envelope_to %></dd>
71+
<dd id="smtp_to"><%= @email.smtp_envelope_to.join(", ") %></dd>
7272
<% end %>
7373

7474
<dt>From:</dt>

railties/test/application/mailer_previews_test.rb

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,11 @@ def foo
509509

510510
get "/rails/mailers/notifier/foo"
511511
assert_equal 200, last_response.status
512-
assert_match "Ruby on Rails &lt;[email protected]&gt;", last_response.body
513-
assert_match "Andrew White &lt;[email protected]&gt;", last_response.body
514-
assert_match "David Heinemeier Hansson &lt;[email protected]&gt;", last_response.body
512+
assert_match '<dd id="from">Ruby on Rails &lt;[email protected]&gt;</dd>', last_response.body
513+
assert_match '<dd id="to">Andrew White &lt;[email protected]&gt;</dd>', last_response.body
514+
assert_match '<dd id="cc">David Heinemeier Hansson &lt;[email protected]&gt;</dd>', last_response.body
515+
assert_no_match '<dd id="smtp_from">', last_response.body
516+
assert_no_match '<dd id="smtp_to">', last_response.body
515517

516518
get "/rails/mailers/download/notifier/foo"
517519
email = Mail.read_from_string(last_response.body)
@@ -521,6 +523,42 @@ def foo
521523
assert_equal ["[email protected]"], email.cc
522524
end
523525

526+
test "message header shows SMTP envelope To and From when different than message headers" do
527+
mailer "notifier", <<-RUBY
528+
class Notifier < ActionMailer::Base
529+
default from: "[email protected]"
530+
531+
def foo
532+
message.smtp_envelope_from = "[email protected]"
533+
message.smtp_envelope_to = ["[email protected]", "[email protected]"]
534+
535+
mail to: "[email protected]"
536+
end
537+
end
538+
RUBY
539+
540+
mailer_preview "notifier", <<-RUBY
541+
class NotifierPreview < ActionMailer::Preview
542+
def foo
543+
Notifier.foo
544+
end
545+
end
546+
RUBY
547+
548+
text_template "notifier/foo", <<-RUBY
549+
Hello, World!
550+
RUBY
551+
552+
app("development")
553+
554+
get "/rails/mailers/notifier/foo"
555+
assert_equal 200, last_response.status
556+
assert_match '<dd id="from">[email protected]</dd>', last_response.body
557+
assert_match '<dd id="smtp_from">[email protected]</dd>', last_response.body
558+
assert_match '<dd id="to">[email protected]</dd>', last_response.body
559+
assert_match '<dd id="smtp_to">[email protected], [email protected]</dd>', last_response.body
560+
end
561+
524562
test "part menu selects correct option" do
525563
mailer "notifier", <<-RUBY
526564
class Notifier < ActionMailer::Base

0 commit comments

Comments
 (0)