Question

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  "my-valid-email@gmail.com" # this is set to my email 
                                           # just for testing purposes and will
                                           # be changed to subscription.email 
    from        "\"my-valid-helo-domain.net\" <noreply@my-valid-helo-domain.net>"
    subject     "Confirm your subscription"
    body        :subscription => subscription
  end
end

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

501 <["noreply@my-valid-helo-domain.net"]>: 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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top