This project is archived and is in readonly mode.

#3078 ✓duplicate
Travis Sinnott

ActionMailer 2.3.3 broke display name support in from address when using SMTP

Reported by Travis Sinnott | August 19th, 2009 @ 05:59 PM

A change made to ActionMailer in 2.3.3 to better support Ruby 1.9 seems to have broken support for display names (eg. "John Smith jsmith@xyz.com") in the from address when using Ruby 1.8 and ActionMailer::Base.delivery_method = :smtp

This can be replicated by setting ActionMailer::Base.delivery_method = :smtp, and creating a simple test mailer:

class TestMailer < ActionMailer::Base
  def test_email
    subject     "this is a test of the 2.3.3 mailer"
    recipients  %(Travis Sinnott <travis.sinnott@gmail.com>)
    from        %(John Smith <jsmith@xyz.com>)
    sent_on     Time.now
  end
end

The specific change in action_mailer/base.rb:

-        sender = (mail['return-path'] && mail['return-path'].spec) || mail.from
+        sender = (mail['return-path'] && mail['return-path'].spec) || mail['from']

http://github.com/rails/rails/commit/1d57ccbc6f80a506e5c38679767933...

The difference between these methods is that the former returns an array of strings containing only the address part (eg. "jsmith@xyz.com"), whereas the later returns a TMail::AddressHeader object.

When passed to Net::SMTP, the value of sender is put directly into the argument for the MAIL FROM command. TMail::AddressHeader.to_s returns "John Smith jsmith@xyz.com", which causes the SMTP server to return a 501 error code:

Net::SMTPSyntaxError (501 < John Smith jsmith@xyz.com>: "@" or "." expected after "John"
): /usr/local/lib/ruby/1.8/net/smtp.rb:930:in check_response' /usr/local/lib/ruby/1.8/net/smtp.rb:899:ingetok' /usr/local/lib/ruby/1.8/net/smtp.rb:828:in mailfrom' /usr/local/lib/ruby/1.8/net/smtp.rb:653:insendmail' /usr/local/lib/ruby/1.8/net/smtp.rb:526:in start' app/models/test_item.rb:9:insend_test_email' app/controllers/test_items_controller.rb:46:in create' app/controllers/test_items_controller.rb:45:increate'

Using delivery_method = :sendmail, or omitting the display name from the address are both effective work-arounds.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Referenced by

Pages