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.

  • DAMI Azzedine

    Hello,
    I’m using this configuration but i get this error :
    SMTP -> get_lines(): $data was “”
    SMTP -> get_lines(): $str is “554 Message rejected: Email address is not verified. ”
    SMTP -> get_lines(): $data is “554 Message rejected: Email address is not verified. ”
    SMTP -> FROM SERVER:554 Message rejected: Email address is not verified.
    SMTP -> ERROR: DATA not accepted from server: 554 Message rejected: Email address is not verified.
    SMTP Error: Data not accepted.

    I note that i’am using a domain with extension .net and address from with extension .ch. The problem is related to this change for extension? What should-I do?

    Thanks.

    • astaz3l

      Hi there,

      Yes, you will probably need to add the particular email(s)/domain to verified senders. You can’t send emails via not verified sender. Easiest way would be to add .ch domain to verified list.

  • Charbel El Azzi

    Hi,
    I think your article is outdated or wrong…
    I spent over a week try to connect my amazon SES server to my Drupal website using SMTP module and by following your tutorial… And i can say that the wrong part is while setting up SMTP Credentials.

    This way is the only way to set up smtp credential for your Drupal website:
    ———————————————————————————————–
    In order to set up the SMTP credentials – username and password in amazon SES.

    1) Go to SMTP SETTINGS
    2) Click on “Create My SMTP Credentials button”.
    3) 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.

    https://uploads.disquscdn.com/images/e0c28d851ed6e35a8aed6f03c84c46dc91e5be8217c05293530fe64ae318b7bc.png

    4) On the next page, you will find a link: “Show User SMTP Security Credentials”. Click on it

    https://uploads.disquscdn.com/images/f84a685e8e54ba9a61cb4831b0122d211ae7cde03729d7d97ba98f8efab294ec.png

    5) And here you will see the “SMTP Username” and “SMTP Password”.
    Be aware that this is the only time these SMTP security credentials will be available for copy or download.

    https://uploads.disquscdn.com/images/1f6f46d845dca6a00c13553bce8b4022cb2a3fe3bd6fc694625f6e06ba9fbb0f.png

    6) Use those SMTP Username and SMTP password as your SMTP Drupal credentials

    Thank you,

    • Dhilip

      Hi,
      Configuring the above SMTP configuration is correct, but need not stop with it, it will just as use default mail still. Because you just enabled SMTP , to use SMTP, still you have to cross some steps
      step 1: Download the Mailsystem ( https://www.drupal.org/project/mailsystem ) latest version
      step 2: Install it in new module(modules page) and enable it and save it.
      step 3: Click a configure button in mail system and now change the ( Site-wide default
      MailSystemInterface class ) to SMTP mail system and save it.

      Now the mail outbounds form drupal forms

      • Krystian

        Hi there,

        Yes, this article is a bit outdated. It was posted on 2014 so not everything might work properly when it was back then. I did not work with Drupal for a long time so I don’t have the opportunity to update this tutorial unfortunately:/

  • Rakesh

    I have followed completely above steps but after that new users did not receive welcome emails from Drupal admin.