Tag Archives: email

Drupal and Amazon SES

Drupal and Amazon SES SMTP server

Hello everyone!

Today I would like to write a bit on configuring SMTP Amazon SES with Drupal. We set up our Drupal installation on Amazon EC2 server. We wanted to change default mail() method in Drupal to SMTP server. As we already used Amazon we wanted to try SES. Here is the short info how we manage to run and configure it.

Setup Amazon SES account for Drupal

I assume that You already have Amazon account for purpose of this tutorial. If You don't have one, you need to sign up in order to use Amazon services first.

After You log in go and visit this page. This is simple dashboard that shows the statistics for Your SMTP server. SES has some limits and You can check them on this page as well.

Drupal - Amazon SES console

Let's set up SMTP account for Drupal. On the left side of Dashboard page you should see sidebar menu. Go to SMTP Settings. Under this page You will have access to data that are required for SMTP access (Server name, port)

Drupal - Amazon SES settings for SMTP

The only thing that we don't have are SMTP credentials - username and password. Click on "Create My SMTP Credentials button". It will take us to IAM page where You can create new user account. You can leave the default name or provide Your own. Click create button. After that You can download the credentials. But keep in mind that there are not the credentials that You'll be using in Drupal!

Drupal - Amazon SES - create user

After new user is created we need to setup his credentials for Drupal purposes. Go to IAM user page and click on Your created user.

Under Security credentials there are Sign-In credentials. Click on Manage Password. You can choose between password generated by IAM or Your own. Pick one of the option and remember the password. That's the one You'll be using in Drupal.

Drupal - Amazon SES - manage password

 

Setup From: account on SES for Drupal

We already have the user credentials for connecting with SMTP server in Drupal. There is one more thing we need to care about. In order to be able to set From: field we need to authorize the email. Go to SES console or click this link. There are two ways of verifying sender. You can authorize specific emails or whole domain.

If You want to authorize specific email (we will use this option) click Verify a new Email Address. Type Your email and click Verify this Email Address. You will receive email with activation link. After activation You should see the status verified.

Drupal - Amazon SES - verify sender email

If You want to authenticate whole domain You need to setup DKIM. You can read more about this process here.

 

Setup Your Drupal installation for Amazon SES

Now this is the final step. We need to configure Drupal for Amazon SES. First, we need a module that can change Drupal's native mail() function to SMTP protocol. In our example we will use SMTP Authentication Support module. It's really nice, easy to implement module for SMTP also with support for Drupal 8. Download and install this module. Go to configuration page (Menu Toolbar -> Configuration -> System -> SMTP Authentication Support).

What fields You need to set:

  • Turn this module on or off - set to ON
  • SMTP server - get the information from SMTP settings page on Amazon
  • SMTP port - 25, 465 or 587 (also listed on SMTP settings page)
  • Use encrypted protocol - Use TLS
  • Username - created username on Amazon SES
  • Password - password for this user (not authentication keys!)
  • E-mail from address - email that You verified

Drupal - SMTP settings for Amazon SES

Rest of the fields are optional. Really useful fields are:

  • E-mail address to send a test e-mail to - You can test if SMTP is working
  • Enable debugging - use it only for test, disable on production enviroment. If the setting doesn't work You will have a debugging messages with information what was wrong.

 

 

Basically that's it. After that You can start sending emails from Drupal using Amazon SES, using forms etc. This module will overwrite default Drupal functionality so You don't have to bother to change anything else. No need to change Your old code for sending emails etc.

Wordpress won't send emails

WordPress won’t send emails

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.

Right direction

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

include:emailserver.com

Or server IP address where 111.222.333.444 is mail server IP

ip4:111.222.333.444

Example:

v=spf1 ip4:180.4.140.130 ~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:

https://www.digitalocean.com/community/articles/how-to-install-and-configure-dkim-with-postfix-on-debian-wheezy

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:)

 

 

Our services: