This project is archived and is in readonly mode.
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:in
getok'
/usr/local/lib/ruby/1.8/net/smtp.rb:828:in mailfrom'
/usr/local/lib/ruby/1.8/net/smtp.rb:653:in
sendmail'
/usr/local/lib/ruby/1.8/net/smtp.rb:526:in start'
app/models/test_item.rb:9:in
send_test_email'
app/controllers/test_items_controller.rb:46:in create'
app/controllers/test_items_controller.rb:45:in
create'
Using delivery_method = :sendmail, or omitting the display name from the address are both effective work-arounds.
Comments and changes to this ticket
-
Travis Sinnott September 3rd, 2009 @ 09:11 PM
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?
-
Levin Alexander September 15th, 2009 @ 12:58 PM
duplicate of #2340, don't know which of the patches is better
-
José Valim September 15th, 2009 @ 07:34 PM
- State changed from new to duplicate
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>
People watching this ticket
Attachments
Tags
Referenced by
- 2340 action mailer can't deliver mail via smtp on ruby 1.9.1 #3078 is a duplicate of this ticket