It's been long time since I wrote something here. But today I decided to wrote the story of my problem with WordPress. In short words - WordPress won't send email. The problem was raised by the clients, they didn't receive emails from WooCommerce with downloadable item. It was huge problem, as payment was processed successfully, but they didn't receive email with PDF they bought.
Research about not working emails in WordPress
I read tons of threads, articles about problems with WordPress emails. Lot of solutions but none of them actually fixed the problem. It pissed me off, because something like that should work without any problems!
Solving the problem with WordPress emails.
I checked few things:
First of all I wasn't sure if it's a problem with WordPress or with WooCommerce. I'm using PayPal only so i turned on debugging in WooCommerce PayPal settings. I tested the transaction, no email sent. I checked the log, and transaction was completed, but no errors on sending email or anything like that.
Error log from apache was empty so it wasn't pure PHP problem or anything like that.
WordPress use default PHP mail() function for sending emails. In hundreds of threads I checked they suggesting using SMTP protocol instead of using mail function. I installed plugin called Check Email. It's simple plugin that checks if WordPress is sending email correctly. I used standard headers for that, typed the email. Check Email told me that email was sent successfully, but it doesn't mean that email will be delivered. I checked my gmail account and no email at all ;/
So I thought, OK, I will switch to SMTP. I installed plugin called WP-Mail-SMTP. All i need was email account where from I will be able to send emails. So I logged in to my server admin panel (DirectAdmin in my case) and created some dummy email. I received all required information for WP-Mail-SMTP plugin like host and port. I filled all require settings field in plugin's settings. Plugin has also great feature where you can test the email. Everything was great, email should be delivered. I checked my gmail account. Still nothing.
That was pretty weird for me. It should have work like a charm! So I decided to log in to fresh created email address and try to send email from there. My server provider has Roundcube system as email system. I created new email and it wasn't delivered. But! I received response email with title: Mail delivery failed: returning message to sender. Email says:
This message was created automatically by mail delivery software. A message that you sent could not be delivered to one or more of its recipients. This is a permanent error. The following address(es) failed: *****@gmail.com SMTP error from remote mail server after end of data: host aspmx.l.google.com [2a00:1450:4013:c01::1a]: 550-5.7.1 [2a01:4f8:101:324d::2 12] Our system has detected that this 550-5.7.1 message is likely unsolicited mail. To reduce the amount of spam sent 550-5.7.1 to Gmail, this message has been blocked. Please visit 550-5.7.1 http://support.google.com/mail/bin/answer.py?hl=en&answer=188131 for 550 5.7.1 more information. i49si3865415eem.12 - gsmtp
I checked the link in the email. Title of this page is Why has Gmail blocked my messages?
First thing that comes to my mind was that I'm on some kind of blacklist. Maybe I'm a spammer? I used http://mxtoolbox.com/ - great tool that checks if you're not blacklisted. My domain was OK, not blacklisted at all.
What comes to my mind, for test i was using @gmail.com email all the time. I tried to send email to other domain and... email was delivered! I read all that I could and it seems that gmail, yahoo, and few other bigger email providers have algorithms that sometimes block domain, server etc. I wasn't able to find complete solution for this problem. Also, i didn't want to contact Google Customer Center or anything like that. Also i was wondering why I've been blocked by Google?
Fixing Google issue
First of all, i had free domain that I got when I bought the server. I created new account to check if server or domain is blocked. I had the same problem with sending emails from this domain so it was obvious to me, that there's something wrong with the server.
Solution 1 - SPF
SPF is Sender Policy Framework that secure SMTP servers from email spam by email spoofing detection. First of all, I need to know what You must add and where. It should be somewhere in Your server admin panel where You can manage DNS settings. If You can't manage the DNS option You will have to ask Your hosting company to add SPF information to Your DNS records.
It's TXT record with this signature:
v=spf1 [server info here] ~all
Where you have to replace [server info here] with
if You have domain server for your mail server where emailserver.com is domain of Your server
Or server IP address where 111.222.333.444 is mail server IP
v=spf1 ip4:22.214.171.124 ~all
Important note is that You must use "From" address, that belongs to SPF enabled domain. If You won't provide this information SPF won't work.
I added the record to my DNS panel. I read in 2 or 3 threads that it helped in WordPress not sending email case. But it didn't helped in my case unfortunately. Maybe it didn't worked but I had anti spoofing protection to non-gmail emails 😀
Solution 2 - DKIM
After some further research I finally found working solution DKIM - DomainKeys Identified Mail. It's a way of associating Your domain name with email message.
Unfortunately for the reader it requires integration with server. Simple DirectAdmin or other panel might be not enough in that case. The simplest way is to contact Your hosting provider and require to setup DKIM for Your domain(s).
If You have access to Your server you can do it by yourself. Here is great tool for generating DKIM keys: http://dkimcore.org/ Installation process is different for every server and it depends of the software and OS you're using. I bet that you can find tutorial for Your OS'x using Google Search. For instance here is the tutorial for Postfix and Debian:
Hope that one of this option will help You solve Your WordPress email sending problem. If You have any other solution that might help solve this issue please post it in comments below:)