This article is based on a speech Amasty Chief Technology Officer Andrei Vachkevich gave on Meet Magento Poland 2014.
Good day to Amasty blog readers! I’ve been working with Magento for more than 5 years, and finally it's time to share some of our recent experience regarding sending e-mails in Magento.
Today I will speak about how to avoid your e-mails being marked as spam. Of course if your goal is not to send spam e-mails.
Many people on Magento related forums are discussing the problem of their e-mails being marked as spam, so I decided to go with this topic and put some light on correct configuration and to create some kind of checklist.
Don't want to set Google reCaptcha up manually? Try out our Magento reCaptcha solution.
The thing is that you don't want any of your e-mails drop into the spam folder. It is very important that e-mails, especially transactional ones, appear in the inbox, otherwise in may lead to customer's confusion.
How spam filters work
First, I will describe shortly how spam filters work - not only with Magento e-mails, of course, but with all e-mails. When an e-mail comes to your server, and you have spam filter enabled, it will check the incoming message for a list of parameters.
Each parameter can affect final spam rating in a negative or positive way. The decision whether the e-mail is spammy or not is based on the final score. Average and recommended by SpamAssassin score to treat e-mail as spam is 6.6. If score is lower - email will go through. If it's higher - it will go into spam folder. In this article I will describe the most common reasons that rise the spam score and provide some tips how to lower it. Fact is: the lower your score is, the more likely your e-mail is going to be received in your subscribers’ inboxes.
The Steps to no-SPAM e-mails in Magento
- Server and IP Configuration
- E-mail Structure
- E-mail Content
- Testing E-mail Messages
To be able to greatly decrease possibility of your e-mails getting into spam folder you must ensure your server is configured correctly and your DNS has all necessary records. The e-mail message you’re sending must contain all required headers and MIME parts. I will also put some light on e-mail makeup. After your server is fine, your e-mail message is ready, the last but not least step is to test your e-mails.
Server and IP configuration for emails in Magento
SPF DNS Record
First of all, you should configure your domain SPF record correctly. SPF record is a TXT record in your DNS that lists all IPs and hostnames that are authorized to send e-mails from your domain. This is not required by all mail servers, however it's highly recommended to keep it right. How it works: when some recipient server gets an e-mail, it checks if IP address that send this message was authorized to do so.
In addition to correct SPF record good practice is to use DomainKeys Identified Mail (DKIM). Your mail server adds a signature to each outgoing e-mail message. The signature can be used to verify sender server by reading public key located in the DNS record of your domain. So you have three parts of the whole: a private key on your server not visible to anyone, that is used to generate email signature; a signature that is included into the e-mail; and a public key listed in DNS TXT record. This is used to verify that this exact e-mail was signed with a private key of a specific server. However this point does not prevent spammers from sending e-mails using, for example, Google servers. This is more likely just an additional layer of security.
When you’re sending an e-mail from a server inside your domain, make sure it has its own IP address and its hostname is resolved to that IP address.
Another necessary DNS record for your domain is MX record. It specifies which mail server is responsible for handling all incoming e-mail for this domain name. This is required in case your e-mail was undelivered to the recipient for some reason, so the recipient server can send undelivered notification.
'White' IP address
Sometimes your IP address may become blacklisted, if you lost your reputation by sending wrong e-mails. After you got a new IP address from your provider, it’s recommended not to use this address for at least a month. The reason behind this is that your new IP address might already be used by someone else before. This 1 month delay lets the IP address get cleared and became 'white'.
A good solution is to use SMTP server to send e-mails in Magento. It can be a public one (such as Gmail, Yahoo and so on, if you trust them), or your private mail server. We at Amasty use our own mail server based on Zimbra. There are also some paid SMTP services available on the web. Also, there are possibilities to use a single server and setup it only once for several Magento projects you run. Magento does not work with SMTP out of the box, so you need an extension for that. The drawbacks are that there are only a few extensions on the market that send e-mails using their own implementation and will not work through SMTP. Also you should maintain the server to make sure it works correctly and is backed up often.
So we have completed the first step, our server is now configured as it should be and is ready to send e-mails out. Let’s proceed to step two and look at the e-mail messages structure.
- has Plain Text MIME part added: it is automatically generated based on HTML version
- has Quote-printable line length for e-mail messages reduced to 75 characters
- and more features for reliable e-mail campaigns.
Recommended e-mail structure in Magento
Plain text part
One of the problems in Magento is that it does not send the text part. It sends only the HTML part of the message, making some spam filters give such messages a higher spam score. The text part can be entered either manually for each e-mail template, or created automatically based on HTML version. In the end of my article I will give some more details on this point. Now let’s move to the next point.
Quote-Printable line length
Quote-Printable is an encoding used in e-mail messages. Based on RFC 2822 specification, each line MUST be no more than 998 characters, and SHOULD be no more than 78 characters in length. While this seems to be a recommendation, it is used to evaluate e-mail message for spam. 76 characters length is, however, recommended. Magento by default uses 200 for quote-printable line length. This can be changed by overriding Zend_Mime class.
Nowadays you cannot imagine an e-mail without images at all. It is good to embed images directly into your e-mail message, but not to link them from remote sources.
Valid 'e-mail HTML'
And now a few words regarding e-mail message body structure. There is one simple rule: 'Back to 90's'.
The rule says: 'Find some old-school HTML developer, ask him to create a historical HTML piece and it will work fine for your e-mail'! It's a joke only partially, this is what you need when it comes to e-mail messages HTML coding. While some web clients and even some desktop clients can display extended HTML like DIV with paddings, most of them will just mess your e-mails up. Use tables, simple HTML with no CSS3. This is what you need for e-mail messages.
These were the major points regarding e-mail structure. Let’s move forward to the next step - e-mail content.
E-mail content recommendations for Magento
It's one of the most important part of the whole article! Bring value. Write text that is important and useful for your readers. Avoid pure marketing strategies aimed at profit only. Always remember that your e-mails are read by humans. I could have written a lengthy blog post on that, but, I believe, it was done by lots of people before.
No single image emails - do HTML coding
Never send e-mails consisting of a single image. I understand it’s sometimes hard to code e-mail markup, however, please do it. Single-image e-mails are mostly treated as customers spam messages.
No to link shorteners
Link shorteners can help you build nice URLs, however, they are considered as untrusted when it comes to e-mails. There is a chance an e-mail will get up to 2 whole points for spam if a shortened link is found inside the content.
We’ve completed all the steps to make our e-mail message almost perfect. Now we need to check if it really is so.
Testing e-mail messages in Magento
3rd party service
So we come to testing e-mail messages. After everything is setup and your message is ready to go, test it first. Check if it looks fine in all common e-mail clients, and also have a look at the spam score.
Okay, now you ask how you can check your e-mail in all apps, because that's not possible to do it manually. Luckily, you can use 3rd party services like Litmus. It will generate previews of your message on different platforms and in different web and desktop e-mail clients. It can also give some suggestions on HTML coding of your e-mails. Very useful tool!
Why you need to test your e-mails at all? Once we sent an e-mail a part of which should have looked like this.
And it looked like this for us. However one of our customers sent us a screenshot showing how he got our message.
Since that time we have been testing e-mail messages. In all major e-mail clients. Always. All of them!
And with PutsMail you can test your e-mail HTML code. It a simple tool that allows you to send the HTML code to your account for design testing and debugging.
Use your team
After you finished with automatic testing, I would recommend sending a few copies to your colleagues or friends. This is a kind of real life experience, and some feedback from live people may be really useful.
Test mobile view
I do hope this information was helpful for you. Do you have any questions on the topic? I'll be happy to answer.