Hi! Thanks for visiting my blog. If you've received any value from my content would you mind supporting my new startup by downloading our browser add-on? It's called PriceBlink and makes online shopping a breeze. You can watch it in action here and download it for Chrome, Firefox, IE, or Safari by going to PriceBlink.com. Thank you and I hope you enjoy!

Properly Formatting Sender Email Address for ActionMailer

Sep 04

If your Rails application does any sort of automated email notification then please keep reading. The reason I say this is that improperly formatted emails, such as the sender’s address, may cause your message to get filtered as spam. When using ActionMailer there’s a simple fix for this. I’m not trying to guarantee successful delivery of all messages, but I think any steps you can take to eliminate the chances of being filtered as spam are necessary. This is such a simple fix that you can’t afford not to do it. The following ActionMailer method demonstrates the way I was initially sending emails from my application:

def new_registration(user)
@subject = ‘Welcome!’
@recipients = user.email
@from = ‘welcome@domain.com’
@body["user"] = user
end

In several email clients this email will show that the message was sent from welcome. Since no formal name is provided the email client tries to pick up the name before the @ symbol. I decided to change this and use the proper delivery format shown here:

def new_registration(user)
@subject = ‘Welcome!’
@recipients = user.email
@from = ‘Dennis Baldwin [dennis@domain.com]‘
@body["user"] = user
end

Now the email will show that it’s from Dennis Baldwin instead of welcome. When testing with gmail my initial messages were being sent to the spam folder. With the new method everything comes through perfectly. Of course the sender’s address is one small part of the equation, but it does help your chances of not getting trashed.

NOTE (11/21/06): as pointed out by Cathy in her comment the from address should consist of angled brackets around “dennis@domain.com”.  WordPress does something funky with my brackets so much sure you use the HTML equivalent of “less than” and “greater than” around the email address.

6 comments

  1. Carl Woodward /

    Hi Dennis,

    The from email address should be ‘Dennis Baldwin ’. This works perfectly.

    Thanks for your help.

    Cheers,
    Carl.

  2. Carl,

    No problem at all and I’m glad to hear it’s working for you. Thanks for pointing my typo out and I’ll get that fixed.

    Regards,
    Dennis

  3. Brett Stauner /

    I am having the same issue, but from reading th above post I do not see a correction to my problem. Did you decide that the fix for you was definitely @from = ‘Name Here <namehere@domain.com>’ I am already doing that, but Istill have trouble getting through to hotmail accounts.

  4. Brett,

    Yeah you’re doing it correctly and it turns out that some of our messages still get filtered as spam when sending to hotmail accounts. It’s completely frustrating and we’ve yet to find a way around it! Please let me know if you find anything out and I’ll do the same.

    Take care,
    Dennis

  5. Thanks Dennis. I found that I had to use angled brackets around the email address and not square ones otherwise the from address came out as blank.

    @from = ‘Dennis Baldwin ‘

  6. Thanks Cathy, I meant to point out in the article those should have been angled brackets. WordPress does funky things with brackets even when I encode them properly! I’m glad this helped :)

Leave a Reply