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:
Connected to 220.127.116.11 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>
X-Spam-Checker-Version: SpamAssassin 3.1.9 (2007-02-13) on emailserver.com
X-Spam-Status: No, score=-2.5 required=7.0 tests=BAYES_00,FORGED_RCVD_HELO
Received: (qmail 6005 invoked from network); 6 Dec 2010 23:10:17 -0500
Received: from appserver.com (HELO ourdomain.com) (18.104.22.168)
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 email@example.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!