This project is archived and is in readonly mode.
action mailer can't deliver mail via smtp on ruby 1.9.1 or 1.8.7
Reported by Friedrich Göpel | March 25th, 2009 @ 05:02 PM | in 2.3.6
Ruby: ruby 1.9.1p0 (2009-03-04 revision 22762) [i386-darwin9.6.0] Rails: edge rails revision: 6ed42ebdff05f9d28a60e91093d8f9afad03a958
Delivering e-mail via smtp on ruby 1.9.1 fails. Turning on debugging in postfix reveals the cause:
MAIL FROM:<["friedrich.goepel@gmail.com"]>
Of course the square brackets are illegal here and make it impossible for the mail server to deliver the mail.
A little digging into action mailer reveals: - in perform_delivery_smtp the sender is passed to Net::SMTP as an Array here:
smtp.sendmail(mail.encoded, sender, destinations)
- it works when changing the line to:
smtp.sendmail(mail.encoded, sender.first, destinations)
- Apparently a Array is passed in ruby 1.8 as well, where it works as is.
- Passing a String works in 1.8 as well.
Now when diffing ruby 1.8 and 1.9.1 net/smtp.rb one finds this:
- def mailfrom( fromaddr )
- getok('MAIL FROM:<%s>', fromaddr)
+ def mailfrom(from_addr)
+ getok("MAIL FROM:<#{from_addr}>")
So it seems this worked before just by sheer accident, multiple senders aren't possible anyway, so passing an Array here makes little sense.
Further investigation leads to the discovery that the Array wrapping happens in TMail, and switching the mail.from to mail['from'] fixes the problem as well and more cleanly.
So here's a oneliner patch to do just that.
Enjoy. :)
Comments and changes to this ticket
-
Joren Six March 29th, 2009 @ 10:36 PM
I can confirm this bug. In postfix it gives this:
warning: Illegal address syntax from unknown[xx.xx.xx.xx] in MAIL command: ["user@example.com"]
The exception in rails itself:
Net::SMTPSyntaxError 501 5.1.7 Bad sender address syntax
Let's hope that this comment makes it easier to google this problem.
Anyway thanks for the fix!
-
korch April 7th, 2009 @ 07:00 PM
+1 from me too, getting the exact same error right now with postfix
-
Friedrich Göpel April 22nd, 2009 @ 04:29 PM
- Tag changed from 2.3.2, actionmailer, bug, edge, email, ruby1.9, ruby19 to 2.3, 2.3.2, 2.3.x, actionmailer, bug, edge, email, patch, ruby1.9, ruby19, smtp
-
Michael Koziarski June 9th, 2009 @ 09:24 AM
- State changed from new to resolved
-
Tom Stuart July 13th, 2009 @ 09:16 AM
This commit broke SMTP sends in my Rails project (on Ruby 1.8).
When the TMail object is instantiated with a From header that includes a recipient name and email address (e.g. "John Doe john@doe.com"),
mail.from
returns just the email address (e.g. "john@doe.com"), which is the correct syntax for SMTP's MAIL FROM command. However,mail['from']
returns the verbatim From string (e.g. "John Doe john@doe.com") which is invalid syntax and causes the SMTP server to barf.Breaking support for named senders in exchange for Ruby 1.9 compatibility isn't an acceptable tradeoff. If you don't want an array, the
sender.first
solution is the right one. -
Michael Koziarski July 13th, 2009 @ 10:10 AM
- State changed from resolved to open
- Milestone changed from 2.x to 2.3.4
Tom,
Can you provide a patch (complete with test case) which demonstrates this problem?
I'm frozen to 2-3-stable and stuff's working ok for me, so I'm obviously doing something wrong.
-
Joey A July 28th, 2009 @ 10:49 PM
Here's a patch that fixes the pre-1.9 issue for me. I've included the tests provided by Josh Nichols at https://rails.lighthouseapp.com/projects/8994/tickets/2945.
-
Michael Koziarski July 29th, 2009 @ 02:49 AM
- Assigned user set to Michael Koziarski
-
Michael Siebert July 31st, 2009 @ 10:50 PM
+1 for Joey A's patch!
just applied it to our production app, it saved our night
this bug is a real showstopper... -
Michael Koziarski August 1st, 2009 @ 09:15 AM
Joey,
Could you attach it as a proper git format-patch patch, that way
you'll get the right credit.Happy to apply to 2-3-stable and master, will be fixed in 2.3.4
-
Josh Nichols August 8th, 2009 @ 04:50 PM
+1, as I was running into it on #2945 :) I verified the patch addresses the problem on 1.8 and 1.9.
Given the mailer:
class Blah < ActionMailer::Base def blah from "Tester McTesty <test@test.com>" recipients "Josh Nichols <josh@technicalpickles.com>" subject "blah" end end
Output before the patch is incorrect for 1.8 and 1.9, according to mailtrap:
* Message begins From: <Tester McTesty <test@test.com>> To: <josh@technicalpickles.com> Body: Date: Sat, 8 Aug 2009 11:43:40 -0400 From: Tester McTesty <test@test.com> To: Josh Nichols <josh@technicalpickles.com> Message-Id: <4a7d9d2ce0ff_540558b421df@technicalpickles.local.tmail> Subject: blah Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 * Message ends
After applying the patch, it is corrected:
* Message begins From: <test@test.com> To: <josh@technicalpickles.com> Body: Date: Sat, 8 Aug 2009 11:42:06 -0400 From: Tester McTesty <test@test.com> To: Josh Nichols <josh@technicalpickles.com> Message-Id: <4a7d9cce149d7_53d158b421c1@technicalpickles.local.tmail> Subject: blah Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 * Message ends
-
Peter Boling August 14th, 2009 @ 07:14 PM
Bug is NOT just on Ruby 1.9.1. I have the problem on Ruby 1.8.7. I assume anything that runs rails 2.3.3 will be unable to send email with a "Name" format.
This is a show stopper. Please release a new rails with this patch! The
-
Dmitry Polushkin August 14th, 2009 @ 09:01 PM
I've added a fix in initializer for Rails 2.3.3 (fix_mailer_on_rails_2.3.3.rb):
module ActionMailer class Base def perform_delivery_smtp(mail) destinations = mail.destinations mail.ready_to_send sender = (mail['return-path'] && mail['return-path'].spec) || Array(mail.from).first smtp = Net::SMTP.new(smtp_settings[:address], smtp_settings[:port]) smtp.enable_starttls_auto if smtp_settings[:enable_starttls_auto] && smtp.respond_to?(:enable_starttls_auto) smtp.start(smtp_settings[:domain], smtp_settings[:user_name], smtp_settings[:password], smtp_settings[:authentication]) do |smtp| smtp.sendmail(mail.encoded, sender, destinations) end end end end
Lets wait till the end of the month, when 2.3.4 will be released.
-
Larry Sprock September 4th, 2009 @ 06:41 PM
Why did this not get applied to rails 2.3.4? Seems like a no brainer. Thanks to Dmitry for a work around.
-
Joshua Siler September 9th, 2009 @ 06:29 PM
Just plowed head long into this issue using 2.3.4 and ruby 1.8. Is the patch in the queue for next release?
-
Curtis Hawthorne September 10th, 2009 @ 03:04 AM
+1 from me. I just ran into this issue after upgrading from 2.2. I'm running ruby 1.8. For now, I'm using Dmitry's workaround, but it would be great to get this in the release.
-
robduncan September 11th, 2009 @ 10:37 PM
- I am also experiencing this issue. Dmitry Polushkin's workaround works for me.
-
Jeremy Kemper September 11th, 2009 @ 11:04 PM
- Milestone changed from 2.3.4 to 2.3.6
[milestone:id#50064 bulk edit command]
-
Josh Nichols September 14th, 2009 @ 09:08 PM
Verified this is a still problem on 2.3.4.
Are there any issues with the attached patches? Would really like to see this fixed so I don't have to monkey patch ActionMailer in an initializer.
-
Levin Alexander September 15th, 2009 @ 11:34 AM
We're using the Patch by Joey A. successfully in production.
+1
-
Joe Van Dyk September 17th, 2009 @ 04:28 AM
So this problem doesn't just happen with ruby 1.9? If so, the ticket title should be updated.
-
Zachery Hostens September 17th, 2009 @ 09:36 AM
in response to Josh Nichol's Post:
Why on earth are emails being sent with multiple From/To lines?
-
Zachery Hostens September 17th, 2009 @ 09:44 AM
nm. i imagine the paste is slightly different than actual output and one is MAIL FROM/RCPT TO, and other is just From/To.
Apologize.
-
Paul Campbell September 18th, 2009 @ 02:09 PM
I got this today on 1.8.6 on Engine Yard, on Rails 2.3.3 and 2.3.4 ....
It's a shame this didn't make it in to 2.3.4 ... seems like it's a pretty serious bug, and I can't imagine too many people using mailers that send with just an email address. It would essentially break any app that relied on named mailers that upgraded to 2.3.3 or 2.3.4.
Is 2.3.5 on the cards soon? Would something like this not warrant a small point release?
-
Gabe da Silveira October 5th, 2009 @ 08:21 PM
I agree with Paul. This bug is nasty. Our site was not sending emails for an hour after deploying. To make matters worse, exception notifier was broken too so we were not notified of the problem. This should be pushed out as a point release immediately. This kind of thing can do real damage to production apps.
-
Christian Seiler October 5th, 2009 @ 08:54 PM
Gabe, I had to go through the exact same. No registration emails, no exception notifications. This is by far the most critical issue I had with Rails so far. And it's a shame that nothing has happened such a long time.
-
Scott Johnson October 28th, 2009 @ 07:22 PM
+1, this is worth a point release by itself. This is a show stopper and it has been broken for months now. A real shame.
-
Christian Seiler October 29th, 2009 @ 08:54 PM
We should start a tweet blast or something to get some awareness
-
thenobot November 4th, 2009 @ 05:38 AM
I had the same problem with ActionMailer 2.2.2 and Ruby 1.8.7-174 with Postfix.
A workaround is to add the following line to your notification methods:
from "Me <noreply@mydomain.com>"
- headers "return-path" => 'noreply@mydomain.com' subject "Here is the Subject!"
Not sure if that works for the versions of ActionMailer and Ruby in question...
-
thenobot November 4th, 2009 @ 05:41 AM
Oh barf, my first post and I mess up the formatting. The workaround looks like:
from "Symantec Health <noreply@symantechealth.com>" + headers "return-path" => 'noreply@symantechealth.com' subject "New Symantec Health Sales Lead!"
-
Nathaniel Bibler November 5th, 2009 @ 07:40 PM
+1 for this issue being seen in production and successful use of Dmitry's initializer code in Rails 2.3.4 with MRI Ruby 1.8.7.
-
owain November 22nd, 2009 @ 06:47 PM
- Tag changed from 2.3, 2.3.2, 2.3.x, actionmailer, bug, edge, email, patch, ruby1.9, ruby19, smtp to 1.8.7, 2.3, 2.3.2, 2.3.x, actionmailer, bug, edge, email, patch, ruby, ruby1.9, ruby19, smtp
- Title changed from action mailer can't deliver mail via smtp on ruby 1.9.1 to action mailer can't deliver mail via smtp on ruby 1.9.1 or 1.8.7
It took an absolute age (4 hours) to find this post. Perhaps a better title such as Net::SMTPFatalError (553) Invalid mail address might make it somewhat easier to search for in future. At least that's what I was getting.
Certainly on ruby 1.8.7
-
owain November 22nd, 2009 @ 07:01 PM
- Tag cleared.
Posted a stub on the Ruby on Rails talk site to help people pick this up.
http://groups.google.com/group/rubyonrails-talk/browse_thread/threa... -
Rob Bean November 27th, 2009 @ 03:36 PM
- Assigned user cleared.
+1 to thenobot's solution.
Using the name and email in "From" and adding the "return-path" header resolved the issue for me.
Ruby 1.8.7
Rails 2.3.4 -
Michael Koziarski November 28th, 2009 @ 12:35 AM
- State changed from open to resolved
Missed 2.3.5 for this one, sorry.
It's resolved in 2-3-stable and master so will be fixed in 3.x and 2.3.6
-
Chris Kampmeier March 28th, 2010 @ 08:57 AM
In case anybody's looking for them, the commits that fix this are
da61a6c9
on 2-3-stable and7e0aa35c
on master.
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
- Aleksey
- Anderson De Andrade
- Andrew White
- Brendan Schwartz
- Chris Schumann
- Christos Zisopoulos
- Curtis Hawthorne
- Dmitry Polushkin
- hhcv
- Jean Vincent
- José Valim
- Josh Nichols
- Joshua Siler
- Ken-ichi Ueda
- Larry Sprock
- Levin Alexander
- LJD
- Martin Andert
- Martin Luder
- Matthew Horan
- Michael Koziarski
- Patrick Gruban
- Peter Bohm
- StuFF mc
- thomas morgan
- travis (at appoxy)
- Travis Sinnott
Attachments
Referenced by
- 2340 action mailer can't deliver mail via smtp on ruby 1.9.1 We're using the Patch by Joey A. successfully in product...
- 3078 ActionMailer 2.3.3 broke display name support in from address when using SMTP duplicate of #2340, don't know which of the patches is be...
- 3078 ActionMailer 2.3.3 broke display name support in from address when using SMTP Yep. This is a duplicate of #2340 / #2945, and Joey A's p...
- 3634 ActionMailer crash dimas, I believe that your problem is a slightly differen...
- 2945 ActionMailer generates invalid SMTP commands when from contains name will fix this in #2340