- Best Practices
Spam Filters & Deliverability: Staying on the Good Side of Mailbox Providers
It has become clear from our support logs that a lot of developers use Action Mailer to send emails. If you are one of these developers you should know that there is one issue that we have seen repeatedly which will cause your emails to get filtered as spam by Gmail: malformed message-ID. This also may occur with other libraries but we see this issue mostly with Action Mailer.
We created our REST API so that you don’t have to worry about technicalities like these (we set a valid message-ID by default) but we understand that you may want to use the tools you are already familiar with.
If you want to use Action Mailer with Mailgun, it’s pretty easy to get started:
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_charset = "utf-8"
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
:authentication => :plain,
:address => "smtp.mailgun.org",
:port => 587,
:domain => "my-mailgun-domain.com",
:user_name => "postmaster@my-mailgun-domain.com",
:password => "my-password"
}
The issue is that if you do not specify the message-ID, Action Mailer populates this header with a default value which may not be a valid message-ID. In addition, if you are connecting to an SMTP relay, that message-ID probably does not reflect the domain that is actually sending the email. It may say something like “<[uid]@localhost.localdomain>”.
Gmail is very strict about making sure that the message-ID in the MIME headers follows RFC 2822and that the domain in the message-ID is the same as the sending domain.
According to the RFC the message-ID should have the following format: “<[uid]@[sendingdomain.com]>”
There is a thread on Stack Overflow about how to set the message-ID in Rails, see example excerpt below:
require 'digest/sha2'
class UserMailer < ActionMailer::Base
default "Message-ID"=>"#{Digest::SHA2.hexdigest(Time.now.to_i.to_s)}@yourdomain.com"
# ... the rest of your mailer class
end
So, make sure to test that the message-ID is getting set correctly or Gmail will junk your emails!
Happy emailing!
Mailgunners
Learn about our Deliverability Services
Looking to send a high volume of emails? Our email experts can supercharge your email performance. See how we've helped companies like Lyft, Shopify, Github increase their email delivery rates to an average of 97%.
Last updated on August 28, 2020
Spam Filters & Deliverability: Staying on the Good Side of Mailbox Providers
3 Secure Email Gateway Holes You Need to Close
How To Avoid Emails Going To Spam
Email Soft Bounces – The Mysteries Of Failures
Spam Traps: What You Should Know
Internet Security – Defending Against Spam
Caught In A Phishing Line – What We Do And How You Can Protect Yourself
The Official Mailgun Ruby Gem Is Here
Weekly Product Update: Improved Reputation System Makes Life Hard On Spammers
Inside The Seedy Underworld Of Spammers And Phishers
InboxReady x Salesforce: The Key to a Stronger Email Deliverability
Become an Email Pro With Our Templates API
Google Postmaster Tools: Understanding Sender Reputation
Navigating Your Career as a Woman in Tech
Implementing Dmarc – A Step-by-Step Guide
Email Bounces: What To Do About Them
Announcing InboxReady: The deliverability suite you need to hit the inbox
Black History Month in Tech: 7 Visionaries Who Shaped The Future
How To Create a Successful Triggered Email Program
Designing HTML Email Templates For Transactional Emails
InboxReady x Salesforce: The Key to a Stronger Email Deliverability
Implementing Dmarc – A Step-by-Step Guide
Announcing InboxReady: The deliverability suite you need to hit the inbox
Designing HTML Email Templates For Transactional Emails
Email Security Best Practices: How To Keep Your Email Program Safe
Mailgun’s Active Defense Against Log4j
Email Blasts: The Dos And Many Don’ts Of Mass Email Sending
Email's Best of 2021
5 Ideas For Better Developer-Designer Collaboration
Mailgun Joins Sinch: The Future of Customer Communications Is Here
Always be in the know and grab free email resources!
By sending this form, I agree that Mailgun may contact me and process my data in accordance with its Privacy Policy.