Remote host said: 555 5.5.2 Syntax error

We have a Rails app that uses a third party SMTP server to deliver email.  Everything was working correctly except emails going to gmail and hotmail addresses were disappearing. It was bizarre. There was no bounce back and email were being delivered to other email hosts.

So we checked the mail logs (much later than we should have when the problem arose, but that’s another story) and saw this entry when delivering to gmail:

<anything@gmail.com>:
Connected to 209.85.147.27 but sender was rejected.
Remote host said: 555 5.5.2 Syntax error.

What the funk? Ok so we checked the headers of the emails and noticed something out of the ordinary:

Return-Path: <“name <noreply”@ourdomain.com>
Delivered-To: email@email.com
X-Spam-Checker-Version: SpamAssassin 3.1.9 (2007-02-13) on emailserver.com
X-Spam-Level:
X-Spam-Status: No, score=-2.5 required=7.0 tests=BAYES_00,FORGED_RCVD_HELO
autolearn=ham version=3.1.9
Received: (qmail 6005 invoked from network); 6 Dec 2010 23:10:17 -0500
Received: from appserver.com (HELO ourdomain.com) (12.34.56.78)
by emailserver.com with SMTP; 6 Dec 2010 23:10:16 -0500

Right off the bat we can see something fishy going on.  Return-Path: <“name <noreply”@ourdomain.com> doesn’t look right at all. It turns out that our email server was incorrectly formatting the return path which was then being rejected by gmail and hotmail.

What to do? There are settings that we could change to specify the Return-Path on the SMTP server but that seemed like it would require a lot of configuration.  So being the lazy developers we are we decided against that. We tried specifying the Return-Path in the Rails ActionMailer model but the mail server was overwriting it. Since this was a live site and emails needed to be delivered to one of, if not the largest (sorry, i didn’t feel like looking up the stats) email providers we decided to just remove the name from the from field so the emails came from noreply@ourdomain.com.

It’s kind of a hacky solution but it worked for us and there aren’t any problems so far. Leave a comment if you have come up with a better solution!

This entry was posted in General and tagged , . Bookmark the permalink.

2 Responses to Remote host said: 555 5.5.2 Syntax error

  1. Ireneusz Skrobiś says:

    The problem is a perform_delivery_smtp method from ActionMailer::Base used in rails 2.3.4 and 2.3.5. You can always try to monkey-patch-it like that:

    
    class ApplicationMailer < ActionMailer::Base
    
      def welcome_email(user)
        recipients user.email from "Site Notifications"
        subject "Welcome!"
        sent_on Time.now
        ...
      end
    
      def perform_delivery_smtp(mail)
        destinations = mail.destinations
        mail.ready_to_send
        sender = mail['return-path'] || mail.from
        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
    
  2. Lorene says:

    Hello admin do you need unlimited content for your page ?
    What if you could copy content from other sites, make it pass copyscape test and publish on your website – i know the right tool for you, just search in google:
    Loimqua’s article tool

Leave a Reply to Ireneusz Skrobiś Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s