Gmail SMTP Plugin for WordPress

Last updated on by admin

Gmail SMTP is an advanced SMTP mailing plugin for WordPress for sending email via Gmail SMTP server. Unlike most SMTP plugins It uses the OAuth 2.0 protocol to authorize access to the Gmail API instead of password authentication.

Gmail SMTP Benefits

1. Gmail SMTP plugin does not store your password. It uses the OAuth 2.0 mechanism for SMTP authentication. It means a more secure login system for users.

2. Gmail SMTP plugin uses PHPMailer – a very popular PHP library used in the core WordPress for sending email. This is to make sure that users can still get full benefits of the default mail functionality.

3. Gmail SMTP plugin takes big headache away from you because you no longer need to Allow Less Secure Apps on your gmail account. This is an option that users had to enable in order to fix SMTP connection issue. This issue went viral from December 2014, when Google started imposing OAuth 2.0 authentication to access their apps. This option affects SMTP mailing because applications that perform password authentication to IMAP, POP, or SMTP are considered Less Secure Apps.

As far as I know this issue still affects almost all the SMTP plugins out there.

How OAuth 2.0 Authorization Works

1. You register a web application in the Google Developers Console.

2. When this application is launched it requests that you give it access to data in your Google account.

3. If you consent, the application receives credentials to access the API.

Requirements

  1. PHP 5.4 or later
  2. A Gmail Account
  3. A self-hosted WordPress site

Gmail SMTP Plugin Summary

Plugin Name: Gmail SMTP
Compatibility: WordPress 4.6
Version: 1.0.6
Description: Connect to Gmail SMTP server to automatically send email from your WordPress site. Configure wp_mail() to use SMTP with OAuth 2.0 authentication.
Icon of Gmail SMTP
Price: 0 USD
Availability: instock
Rating: 4.4 out of 25 votes

Installation

You can install the Gmail SMTP plugin in one of the following ways:

Option 1 (Quick & Easy install)

  1. Go to Plugins->Add New from your WordPress admin dashboard
  2. Search for Gmail SMTP
  3. Click Install once you have found it

Option 2 (Manual install)

  1. Download the zip version of the plugin
  2. Go to Plugins->Add New
  3. Click Upload Plugin
  4. Select the zip file on your computer
  5. Install it

Gmail SMTP Configuration

In order to get started with the plugin go to Settings->Gmail SMTP from your admin dashboard.

screenshot of gmail smtp plugin menu

Settings

1. Click on the web application link in the plugin settings.

screenshot showing how to go to the google web application link from the gmail smtp plugin settings

2. Login to your Google account which will be used to send email.

3. Create a new project where your application will be registered.

screenshot showing how to register an application for gmail in the Google Developers Console

4. Once the project is created Gmail API should be automatically enabled.

5. Click Go to credentials.

screenshot showing that gmail api has been enable on the project

6. Click Add Credentials and select OAuth 2.0 client ID.

screenshot showing how to add oauth credentials to access gmail api

7. Click Configure consent screen.

screenshot showing how to configure consent screen to create an oauth client id

8. Enter a product name for the OAuth consent screen (e.g. Gmail SMTP) and click Save.

screenshot showing the oauth consent screen in the google developers console

9. Now that the OAuth consent screen has been configured you can create a Client ID for it. Set the application type to Web application and enter a name for it (e.g. Gmail SMTP).

10. Copy the Authorized Redirect URL from the settings and paste it into the field here.

screenshot showing how to create a client id by creating a new web app in the google developers console

11. Click Create. This will generate a Client ID and Client Secret for you. Copy and paste them into the settings are of the plugin.

12. Configure the rest of the settings. It includes,

OAuth Email Address: The email address that you will use for SMTP authentication. This should be the same email used in the Google Developers Console.

From Email Address: The email address which will be used as the From Address when sending an email.

From Name: The name which will be used as the From Name when sending an email.

Type of Encryption: The encryption which will be used when sending an email (either TLS/SSL). By default it should be set to TLS since SSL has been deprecated since 1998.

SMTP Port: The port which will be used when sending an email. If you choose TLS it should be set to 587. For SSL use port 465 instead.

13. Click Save Changes.

Now that you have configured the settings a Grant Permission button will appear.

screenshot showing how to grant permission from the gmail smtp settings

14. Clicking on it will take you to a consent screen where you will be able to grant this app access to the Gmail API.

allow application screen of google developers console

15. When you click Allow you will get redirected back to the plugin settings. You should see a message like Access Granted Successfully. The SMTP Status should also get set from Not Connected to Connected.

screenshot of gmail smtp settings

That’s it. Gmail SMTP plugin will now be able to take control of all outgoing email from your website.

Test Email

In order to test the email functionality you can send a test email from the Test Email tab.

Debug option is enabled by default for the test email functionality – which means you would be able to see if the plugin was able to send the email without any error.

screenshot showing how to send a test email from the gmail smtp plugin settings

Troubleshooting

By default, your SMTP port should be configured on 587 (with TLS encryption). If you can’t get it to work then you can try changing it to 465 (with SSL encryption).

If you still can’t get either to work try port 25 with TLS first and then SSL. Please note that most servers don’t support encryption on port 25, which is why port 587 and 465 are the preferred options.

smtp connect() failed

If you are connecting to the Gmail SMTP server for the first, you might get an error: smtp connect() failed or Could not authenticate.

This error usually occurs when Gmail blocks a SMTP connection made from an external server. This is not a configuration issue. Gmail does it time to time for security reasons. In order to fix this issue login to your Gmail account first. You should see a security warning from Gmail upon login – “Your account has been hacked” or “Somebody stole your password”. As soon as you confirm that it was you who tried to login (Just click on the link that shows up in that message), the plugin should be able to connect to the Gmail SMTP server.

OpenSSL Certificate Verification Failure

As of PHP 5.6 you will get the following error/warning if the SSL certificate on the server is not properly configured:

Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

In order to fix this issue your web host needs to replace this invalid, misconfigured or self-signed certificate with a good one. The other alternative is to check this option in the settings so PHP doesn’t verify the certificate – “Disable SSL Certificate Verification”. That said, I wouldn’t recommend it since this change was made for a good reason.

Removing Access From the Application

For some reason if you ever want to stop using this plugin or do a fresh authorization this option might come in handy.

Revoke Access menu allows you to remove access from a previously authorized application.

screenshot showing the revoke access settings of gmail smtp plugin

First, you need to click on the account settings link. This will take you to a page where you can remove access from the Gmail SMTP application.

screenshot showing how to remove access from an application in the google developers console

Once you have removed access from it, go back to the Remove Access tab in the plugin settings and delete the Access key.

Access key is a token received by the plugin when you first granted your app access to the Gmail API. This token is needed to communicate with the Gmail API and send email. In order to avoid any confusion the plugin does not show it on the settings page.

Once this token is deleted the plugin can no longer connect to the Gmail SMTP server or send email. This means you will need to reauthorize (using the web application link in the settings) before you can start using the plugin again. However, you won’t need to do set up everything from scratch as long as the project still exists in your Google Developers Console. It will start from the Allow consent screen.

If you have any questions feel free to share it in the comment section.

If you like Gmail SMTP please leave it a rating. A huge thanks in advance!

Limited Time Offer!

Bluehost WordPress Hosting – $2.95/month (Free domain, Free Site Builders, Unmetered bandwidth)

SiteGround WordPress Hosting – $3.95/month (Free Domain, Free SSL, Free CloudFlare CDN)

125 thoughts on “Gmail SMTP Plugin for WordPress”

  1. Hi,
    I’ve followed all the intructions and I’m getting the following error bellow. Any ideas? Tried every combinations of ports and encriptions with no success.

    Thanks

    SERVER -> CLIENT: 220 2.0.0 Ready to start TLS

    Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in /home/storage/9/08/35/agenciagdm/public_html/wp-content/plugins/gmail-smtp/PHPMailer/class.smtp.php on line 343
    SMTP Error: Could not connect to SMTP host.
    CLIENT -> SERVER: QUIT
    SMTP -> get_lines(): $data is ""
    Connection: closed
    SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
    Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

    1. @Ricardo, It looks like there is an issue in your SSL configuration.

      https://github.com/PHPMailer/PHPMailer/issues/368

      I can add a tweak in the plugin so it doesn’t verify the certificate. But I think you should try to get your hosting to fix the certificate (PHP 5.6 made this change for a good reason).

      1. I have released an update to address this issue. You can now disable SSL certificate verification in the settings, If you are unable to get your host to fix SSL configuration on the server.

  2. Hi, i’ve followed all the instructions and have this error

    SMTP Error: Could not authenticate.
    CLIENT -> SERVER: QUIT
    SMTP -> get_lines(): $data is ""
    SMTP -> get_lines(): $str is "221 host.t2tagency.com closing connection"
    SERVER -> CLIENT: 221 host.t2tagency.com closing connection
    Connection: closed
    SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

    It’s a problem with the server?

  3. Really great plugin! I already have it running on a couple of client sites.

    Im encountering one annoying thing though – I can’t seem to change the “From Email Address” – everytime I receive an email the from email is always the defined “OAuth Email Address”.
    It seems that the defined “From Email Address” is ignored.

    Note: The email I have defined in “From Email Address” is a custom@clientdomain.com = not a gmail/google domain, not sure if that has anything to say?

    When sending the test email I see the correct “From Email Address”, however when I receive the email and reply to it, then it shows the “OAuth Email Address”.

    Anyone experienced the same issue?

    TEST EMAIL SNIPPET:
    CLIENT -> SERVER: Date: Wed, 11 May 2016 22:08:31 +0000
    CLIENT -> SERVER: To: my@email.com
    CLIENT -> SERVER: From: Company
    CLIENT -> SERVER: Subject: Test mail

    1. ok the EMAIL SNIPPET didn’t print out well in the comment 🙂 Eitherways, bottomline is that I see the right “From Email Address” in the test email log

  4. Hi,

    I am facing an unusual problem in that the configuration seems fine and the test email response doesn’t mention any errors, but none of the test emails are actually reaching their destinations. Here are some more details about my setup:

    Google: Using Google Apps for Business. Have set up OAuth as suggested and the Gmail SMTP settings shows a green checkmark.

    Domain: Domain is on Godaddy. MX records were set by Google Apps for Business automatically when I had signed up with them for email. I am unable to find any settings on Godaddy where I can change MX settings to “remote”, so that is one of the few steps from previous comments that I could not properly follow.

    Hosting: Hosting is on Digital Ocean.

    On trying to send Test Email, this is what I get:

    Connection: opening to ssl://smtp.gmail.com:465, timeout=300, options=array ()
    Connection: opened
    SMTP -> get_lines(): $data is ""
    SMTP -> get_lines(): $str is "220 smtp.gmail.com ESMTP q19sm6609949qhb.20 - gsmtp"
    SERVER -> CLIENT: 220 smtp.gmail.com ESMTP q19sm6609949qhb.20 - gsmtp
    CLIENT -> SERVER: EHLO allonzy.in
    SMTP -> get_lines(): $data is ""
    SMTP -> get_lines(): $str is "250-smtp.gmail.com at your service, [162.243.2.17]"
    SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [162.243.2.17]"
    SMTP -> get_lines(): $str is "250-SIZE 35882577"
    SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [162.243.2.17]250-SIZE 35882577"
    SMTP -> get_lines(): $str is "250-8BITMIME"
    SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [162.243.2.17]250-SIZE 35882577250-8BITMIME"
    SMTP -> get_lines(): $str is "250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH"
    SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [162.243.2.17]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH"
    SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES"
    SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [162.243.2.17]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES"
    SMTP -> get_lines(): $str is "250-PIPELINING"
    SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [162.243.2.17]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING"
    SMTP -> get_lines(): $str is "250-CHUNKING"
    SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [162.243.2.17]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING"
    SMTP -> get_lines(): $str is "250 SMTPUTF8"
    SERVER -> CLIENT: 250-smtp.gmail.com at your service, [162.243.2.17]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
    Auth method requested: XOAUTH2
    Auth methods available on the server: LOGIN,PLAIN,XOAUTH2,PLAIN-CLIENTTOKEN,OAUTHBEARER,XOAUTH

    My Server Details:

    OS: Linux ubuntu-512mb-nyc2-01 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64
    PHP version: 5.5.9-1ubuntu4.14
    WordPress version: 4.5.1
    WordPress multisite: No
    openssl: Available
    allow_url_fopen: Enabled
    stream_socket_client: Available
    fsockopen: Available

    Any idea on how to troubleshoot this? I am at a dead-end. I have no other mail plugins setup.

    1. I sorted it out! 🙂

      On checking the apache2 error logs, found that curl_inti() was not being found. Basically, curl was not installed on the server. Installed php5-curl, restarted server and the test email went through.

      Thanks for the awesome plugin! 😀

  5. Hi Admin,

    I’m having problem in grant permission. I keep getting HTTP ERROR 500: MySite is currently unable to handle this request. Where it cannot redirect after I click ALLOW
    My Server:

    OS: Windows NT NSTPNIE 5.2 build 3790 (Windows Server 2003 R2 Standard Edition Service Pack 2) i586
    PHP version: 5.4.31
    WordPress version: 4.5.2
    WordPress multisite: No
    openssl: Available
    allow_url_fopen: Enabled
    stream_socket_client: Available
    fsockopen: Available

    1. @Hardy, I can’t really troubleshoot this since I’m not logged into your gmail account. If it’s an issue on the developers console you should probably try it again later.

      1. Ok, do you what this error mean:

        Fatal error: Uncaught exception 'Google_IO_Exception' with message 'Failed to connect to accounts.google.com port 443: Timed out' in X:\XXX\XXX\wp-content\plugins\gmail-smtp\google-api-php-client\src\Google\IO\Curl.php:115 Stack trace: #0 X:\XXX\XXX\wp-content\plugins\gmail-smtp\google-api-php-client\src\Google\IO\Abstract.php(136): Google_IO_Curl->executeRequest(Object(Google_Http_Request)) #1 X:\XXX\XXX\wp-content\plugins\gmail-smtp\google-api-php-client\src\Google\Auth\OAuth2.php(111): Google_IO_Abstract->makeRequest(Object(Google_Http_Request)) #2 X:\XXX\XXX\wp-content\plugins\gmail-smtp\google-api-php-client\src\Google\Client.php(128): Google_Auth_OAuth2->authenticate('4/VcjFJ9yZzCgPx...', false) #3 X:\XXX\XXX\wp-content\plugins\gmail-smtp\class.phpmaileroauthgoogle.php(99): Google_Client->authenticate('4/VcjFJ9yZzCgPx...') #4 X:\XXX\XXX\wp-content\plugins\gmail-smtp\main.php(132): GmailXOAuth2::resetCredentials('4/VcjFJ9yZzCgPx...') #5 [internal function]: GMAIL_SMTP->plugin in X:\XXX\XXX\wp-content\plugins\gmail-smtp\google-api-php-client\src\Google\IO\Curl.php on line 115

        1. @Hardy, I’m not sure what this error means either. I did some research with the error message. Some users are saying it’s a firewall issue on the server.

  6. Connection: opening to ssl://smtp.gmail.com:465, timeout=300, options=array ()
    SMTP ERROR: Failed to connect to server: Connection refused (111)
    SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

    OS: Linux n1plcpnl0005.prod.ams1.secureserver.net 2.6.32-673.8.1.lve1.4.3.el6.x86_64 #1 SMP Wed Feb 10 08:57:30 EST 2016 x86_64
    PHP version: 5.4.43
    WordPress version: 4.5.2
    WordPress multisite: No
    openssl: Available
    allow_url_fopen: Enabled
    stream_socket_client: Available
    fsockopen: Available

    I am using google apps gmail. Tell me whats going on please. 🙂

  7. I get the following error:

    “400. That’s an error.

    Error: invalid_request

    Missing required parameter: client_id”

Leave a Reply