If you suddenly find out no customers are reaching to you for weeks, will you be paranoid?

Drupal, like many other CMS, do not send mails by itself. By default, it calls the PHP sendmail() function and the rest of the job is taken care by your hosting server. When it functions like expected, there is no need to worry.

One day, I realized that I had not received any emails from my customers using the contact form on my Drupal website. It happended for a couple of weeks. At the result, I lost money. Customers could not contact me so they went away.

I worked with my hosting provider to investigate the problem, and there are two possible reasons:

  1. The sendmail() function is not working properly
  2. The server is marked as spamming. Other websites on the same server may send too many emails, so the server IP is black listed.

Whatever the reason is, I can not go with default mailing function provided by my hosting anymore. It is risky to my business.

So I found SMTP module for Drupal. It allows to send mail directly to an outside SMTP server, for example, Gmail. This combo of SMTP module and Gmail is much more stable which I apply to many client websites as well.

Install the SMTP module

Step 1: Download the SMTP module for Drupal: https://drupal.org/project/smtp

Step 2: Extract to /sites/all/modules

Step 3: Enable the module on Admin - Modules

Step 4 (for Drupal 6 only): you have to install the PHPMailer package from Codeworx Tech., version supported is below 2.2.1. Place it in a directory named "phpmailer" in /sites/all/modules/smtp

For Drupal 7, this is no longer required. The SMTP module for Drupal 7 is shipped with the PHP Mailer. It works out-of-the-box 

Configure with Gmail account

Step 1: Pls go to Admin - Configuration - SMTP Authentication Support

Step 2: On Install Options, please choose On

Step 3: On SMTP server setting, please enter

  • SMTP server: smtp.gmail.com
  • SMTP backup server: <blank>
  • SMTP port: 465
  • Use encrypted protocol: Use SSL

If the combination of SSL and port 465 does not work, pls try TLS and port 587

Step 4: On SMTP Authentication: Enter user name and password of your Gmail account.

Step 5: On Email options: Enter your email from address (could be noreply@yourwebsite.com) and email from name (could be your site name).

Step 6: On Send test email: enter a email to test whether the module is working. Click on Save and go to your inbox to check. If there is an testing email then it is fine. 

If it does not work, you may need to tick on the option "Enable debugging" and send a test email. The responses will be printed so you know more about the problem.

I attach the screenshot of a SMTP configuration.

Configure Drupal SMTP module with Gmail

You may need to turn on Less secure apps access on your Google account in order to this smtp authentication to work.

Update: after 31/5/2022, you must use App Password

As announced by Google, the Less secure app access will be terminated after 31/5/2022.

So you will need to do this on your Google account:

  1. Enable 2 steps verification
  2. Create a new App Password and use it on the SMTP configuration page.

The official guide on Google is here: https://support.google.com/accounts/answer/185833

If you find this article is useful, please subscribe to our newsletter. More interesting posts will be sent to you periodically.

By Thanh Le

Subscribe to our mailing list

* indicates required