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.

This project is archived and is in readonly mode.

ActionMailer generates invalid SMTP commands when from contains name

#2945

After upgrading to 2.3.3, I began getting this error when delivering mail over SMTP:

Net::SMTPSyntaxError: 501 <"Fan Vs. Fan Notification" <do_not_reply@fanvsfan.com>>: "@" or "." expected after ""Fan Vs. Fan Notification""
/usr/lib64/ruby/1.8/net/smtp.rb:679:in `check_response'
/usr/lib64/ruby/1.8/net/smtp.rb:652:in `getok'
/usr/lib64/ruby/1.8/net/smtp.rb:630:in `mailfrom'
/usr/lib64/ruby/1.8/net/smtp.rb:543:in `send0'
/usr/lib64/ruby/1.8/net/smtp.rb:471:in `sendmail'
vendor/rails/actionmailer/lib/action_mailer/base.rb:683:in `perform_delivery_smtp'
/usr/lib64/ruby/1.8/net/smtp.rb:378:in `start'
vendor/rails/actionmailer/lib/action_mailer/base.rb:681:in `perform_delivery_smtp'
vendor/rails/actionmailer/lib/action_mailer/base.rb:523:in `__send__'
vendor/rails/actionmailer/lib/action_mailer/base.rb:523:in `deliver!'
vendor/rails/actionmailer/lib/action_mailer/base.rb:395:in `method_missing
lib/debatable.rb:428:in `send_notification'

The code that was used is something along the lines of:

class Mailer < ActionMailer::Base

  def debate_challenge_notification(user, debate)
     from "Fan Vs. Fan Notification" <do_not_reply@fanvsfan.com>"
     # snip for brevity
  end
end

I popped open mailtrap to see what it was actually sending over the line, and it was:

Helo: EHLO mydomain.net
Seen an EHLO
From: MAIL FROM:<"Fan Vs. Fan Notification" <do_not_reply@fanvsfan.com>>
To: RCPT TO:<josh@technicalpickles.com>
+ Date: Wed, 22 Jul 2009 22:47:11 -0400
+ From: "Fan Vs. Fan Notification" <do_not_reply@fanvsfan.com>

The problem is that it's wrapping the entire 'from' with less-than and greater-than. I looked back at what it was doing before 2.3.3, and it seems to behave correctly:

From: MAIL FROM:<do_not_reply@fanvsfan.com>
To: RCPT TO:<josh@technicalpickles.com>
+ Date: Wed, 22 Jul 2009 23:26:19 -0400
+ From: "Fan Vs. Fan Registration" <do_not_reply@fanvsfan.com>

After digging around ActionMailer and TMail, I found traced the difference to this commit:

http://github.com/rails/rails/commit/72d111a21ca21460a320d7611b1fdf...

The commit message says it's for a 1.9 issue, but it looks that mail['from'] returns exactly the thing you specified in the mailer, whereas the old way of just returns the email part of it. I've created some tests which expose this problem, but I'm not sure of the best way to fix it and have it work with 1.9.

Reported by Josh Nichols · July 23rd, 2009 @ 06:24 PM

State: duplicate
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Maxi Musi
    Maxi Musi

    Maybe my error comes from the same issue:

    users#create (Net::SMTPFatalError) "555 5.5.2 Syntax error. 24sm4141505bwz.87\n"

    I'm using Ruby 1.8.7!

    Error occured when switching to Rails 2.3.3. When I backswitch it works again.
    Cannot provide further information, sorry.

    July 28th, 2009 @ 09:32 AM

  2. Joey A
    Joey A

    The patch I uploaded at

    https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets...

    fixes this issue for me in ruby 1.8.6. Josh, I included your tests there.

    July 28th, 2009 @ 10:53 PM

  3. Michael Koziarski
    Michael Koziarski
    • State changed from new to duplicate

    will fix this in #2340

    July 29th, 2009 @ 02:49 AM