views:

730

answers:

2

I'm having trouble sending mail using SMTP from a Rails app. I have a Mailer class:

class Mailer < ActionMailer::Base
  def newsletter_confirmation(subscription)
    recipients  "[email protected]" # this is set to my email 
                                           # just for testing purposes and will
                                           # be changed to subscription.email 
    from        "\"my-valid-helo-domain.net\" <[email protected]>"
    subject     "Confirm your subscription"
    body        :subscription => subscription
  end
end

When I try to send the mail, I get a Net::SMTPSyntaxError:

501 <["[email protected]"]>: missing or malformed local part

If I comment out the from field, the mail gets delivered ok, but with the from information missing (obviously).
Any ideas on what I'm doing wrong?

Thanks.

Edit: I'm using Rails 2.3.2 and Ruby 1.9.1

+2  A: 

The error code and the description of the error states that this is an error on the mail server.

I suggest you check the mail servers to pinpoint the error.

When it comes to ActionMailer it is supposed to raise an exception if the configuration parameter raise_delivery_errors is set (default in Production but not in Development I believe), so you can check that one and try to resend if it triggers.

EDIT:

Here is the solution (it's a Ruby/Rails 1.9 bug):

https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2340-action-mailer-cant-deliver-mail-via-smtp-on-ruby-191

and the patch:

https://rails.lighthouseapp.com/projects/8994/tickets/2340/a/104008/action_mailer-ruby-1.9-from-address-fix.patch

Lichtamberg
You are right about ActionMailer not raising exceptions in "development" by default, but I changed raise_delivery_errors = true so that I can see what is happening. I'll try with the mail server to get more info on the error. Thanks.
andi
The only problem is that the mail server is on shared hosting environment and I don't have access to the logs. So I guess I'll have to figure out from this error message. Do you happend to know if there are more than one problem that can lead to this error code/message?
andi
Did you tried with a different mail address format?f.e. only "[email protected]"
Lichtamberg
Yes, I tried different formats (with name, without name) and different addresses. Still, no luck.
andi
Maybe its this problem?https://rails.lighthouseapp.com/projects/8994/tickets/2853-actionmailer-cannot-set-from-header-with-smtp
Lichtamberg
Do you use restful_authentication?
Lichtamberg
And do you use Rails 2.3.2?
Lichtamberg
I *am* using Rails 2.3.2, *and* ruby 1.9 but not restful_authentication. This looks similar to my problem, though. I'll look over it and let you know.
andi
Actually, it looks like this is the problem: https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2340-action-mailer-cant-deliver-mail-via-smtp-on-ruby-191
andi
Fine that you found the solution.
Lichtamberg
andi
Thanks! You are welcome!
Lichtamberg
+1  A: 

It is a known bug. https://rails.lighthouseapp.com/projects/8994/tickets/2340