Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

There was a problem

You must be a member of this account.

This project is archived and is in readonly mode.

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

#3078

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.

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

State: duplicate
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Travis Sinnott
    Travis Sinnott

    Adding patch to fix for both Ruby 1.8 and 1.9. Uses first element of the mail.from array instead of entire array or TMail::AddressHeader object.

    Thoughts?

    September 3rd, 2009 @ 09:11 PM

  2. Myron Marston
    Myron Marston
    1. Fixed the problem for me.

    September 7th, 2009 @ 07:26 PM

  3. Ger Hartnett
    Ger Hartnett

    Worked for me too on 2.3.4. Thanks Travis.

    September 10th, 2009 @ 06:29 PM

  4. Jarred Nicholls
    Jarred Nicholls

    Yep, good fix, thanks. Hope it's in 2.3.5 =)

    September 15th, 2009 @ 05:10 AM

  5. Levin Alexander
  6. Travis Sinnott
  7. José Valim
    José Valim
    • State changed from new to duplicate

    September 15th, 2009 @ 07:34 PM