Gmail SMTP Plugin for WordPress

Gmail SMTP is an advanced SMTP mailing plugin for WordPress for sending an 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 wordpress plugin

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 an email. This is to make sure that users can still get full benefits of the default email functionality.

3. Gmail SMTP plugin takes a 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.

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 naa986”
  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

Gmail SMTP Project Creation

1. Go to console.cloud.google.com/apis/dashboard.

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

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

screenshot showing how to create a new project in the Google Developers Console

It doesn’t have to be “Gmail SMTP Project 1”. You can name it whatever you like. I chose a meaningful name because I have multiple projects in it.

Credentials/App Creation

1. Once the project is created go to Credentials > CREATE CREDENTIALS and select OAuth client ID.

2. In order to create an OAuth client ID, you need to configure the OAuth consent screen first. So click CONFIGURE CONSENT SCREEN.

screenshot showing how to configure the consent screen when creating an OAuth Client ID

3. Choose how you want to configure and register your app. Since I’m not using G Suite I had to choose External.

screenshot showing how to choose a user type in the oauth consent screen of the google developers console

4. Enter a name (e.g. Gmail SMTP) for the OAuth consent screen.

screenshot showing the OAuth consent screen 2 in the google developers console

5. You can configure optional fields such as Authorized domains, Application home page, Application privacy policy link and Application terms of service link (I was able to skip all and click SAVE AND CONTINUE). You do however need to enter an email address under the Developer contact information section.

screenshot showing part 2 of the consent screen 2 in the google developers console

6. Skip the Scopes screen.

screenshot showing the Scopes tab in the OAuth consent screen of the Google cloud console

7. Add a test user if you plan to use this app in test mode (This is not required if you want to publish it).

screenshot showing the Test users tab in the OAuth consent screen of the Google cloud console

8. Keep your app in test mode or publish it. If the Publishing status is set to In production, a warning message (This app isn’t verified) may appear on the consent screen that you can easily skip.

screenshot showing the Summary tab in the OAuth consent screen of the Google cloud console

Now that the OAuth consent screen has been configured you can create an OAuth Client ID.

9. Go to the Credentials tab and select OAuth client ID under CREATE CREDENTIALS.

screenshot showing how to select OAuth client Id under CREATE CREDENTIALS in the google developers console

10. Set the application type to Web application and enter a name for it (e.g. Gmail SMTP App). 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 area of the plugin.

Gmail SMTP Settings Configuration

1. 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.

2. 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

3. 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

4. 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.

Fresh Authorization / 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 that the plugin received when you first granted your app access to the Gmail API. This token is necessary to communicate with the Gmail API and send an email. In order to avoid any confusion, the plugin does not show it on the settings page.

Once you delete this token the plugin can no longer connect to the Gmail SMTP server or send an 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 set up everything from scratch as long as the project still exists in your Google Developers Console.

Gmail SMTP Add-ons

Gmail SMTP plugin comes with add-ons that you can use to enhance its functionality on your website.

Reply-To

Reply-To add-on lets you set a reply-to address for all outgoing email messages.

Cc

Cc add-on lets you set a cc recipient for all outgoing email messages.

712 thoughts on “Gmail SMTP Plugin for WordPress”

  1. Hello Admin,

    Great plugin Thank you..

    Question: When someones uses my form to send me emails I get the email but when I try to reply to it.. its from myself email address .. so it repeats my email .. How can I fix this so it shows the other person email address and I can just reply to it?

    Thank you

    Reply
    • @Marios, When using SMTP you are basically sending an email from your account to the recipient (Not from the contact form on your server). That’s why Gmail is automatically putting your actual Gmail address as the reply-to email. That same goes for From email address. The plugin does pass this information to Gmail but it simply ignores them for security reasons.

      Reply
  2. Any thoughts on why this is failing? I do get the notification that GMAIL STMP is controlling the email and I should remove it. There was no option to approve.

    Connection: opening to smtp.gmail.com:587, timeout=300, options=array ( ‘ssl’ => array ( ‘verify_peer’ => false, ‘verify_peer_name’ => false, ‘allow_self_signed’ => true, ),)
    Connection: Failed to connect to server. Error number 2. “Error notice: stream_socket_client(): unable to connect to smtp.gmail.com:587 (Network is unreachable)
    SMTP ERROR: Failed to connect to server: Network is unreachable (101)
    SMTP connect() failed. github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

    Servo Info:
    OS: Linux box1085.bluehost.com 3.12.74-20170619.148.ELK6.x86_64 #1 SMP Mon Jun 19 19:48:05 CDT 2017 x86_64
    PHP version: 5.6.29
    WordPress version: 4.8.1
    WordPress multisite: No
    openssl: Available
    allow_url_fopen: Enabled
    stream_socket_client: Available
    fsockopen: Available
    cURL: Available
    cURL Version: 7.24.0, OpenSSL/1.0.0

    Thanks,
    George

    Reply
    • @George, Bluehost may have blocked port 587 on your server. Please contact them to make sure port 587 is open and supports TLS encryption.

      Reply
      • I get the same error with port 465 and I have had other smtp plugins that I could get test emails through port 465.

        Thanks,
        George

        Reply
      • I am also getting this error. Tried 587, 465, 25 with SSL and TLS, no dice. Always get:

        unable to connect to ssl://smtp.gmail.com:25 (Network is unreachable)

        Any help guys?

        Reply
        • @Tim, Port 25 usually doesn’t support encryption. Please try TLS encryption on port 587. You also need to contact your host to make sure that port 587 is open and supports TLS encryption.

          Reply
  3. This morning, I got one test email on port 587 through. It took a while, but it came through. All other tests this morning on port 587 and 465 have all had timeout errors. I guess the bluehost site or gmail server is just very slow.

    Thanks,
    George

    Reply
  4. Hello, Gmail SMTP seems to conflict with the Use-Your-Drive plugin, which is using V3 of the google api. Is there any way to get Gmail SMTP to use V3 as well? See this link for more info: florisdeleeuwnl.zendesk.com/hc/en-us/articles/214584903-Error-400-Invalid-field-selection

    Thanks!

    Reply
    • @Chris, Thank you for the feedback. I will work on updating the Google API library in the plugin.

      Reply
  5. Love you, you helped me solve a problem for my woocommerce sending out automatic email through GSuite! Huge thanks!!!!

    Reply
    • What hosting provider are you using – if you don’t mind me asking. I would like to use the same workflow with my wpforms, but 1and1 hosting provider does not play nice with gmail SMTP. Looking to jump ship on 1and1

      Reply
  6. Connection: opening to smtp.gmail.com:587, timeout=300, options=array ( ‘ssl’ => array ( ‘verify_peer’ => false, ‘verify_peer_name’ => false, ‘allow_self_signed’ => true, ),)
    Connection: Failed to connect to server. Error number 2. “Error notice: stream_socket_client(): unable to connect to smtp.gmail.com:587 (Connection timed out)
    SMTP ERROR: Failed to connect to server: Connection timed out (110)
    SMTP connect() failed. github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

    I had a successful install of the gmail plugin , green connected ready to go and I get this error from my test email. I am running debian 8. Any suggestions? Do I need to still install postfix or another smtp mail app on debian???

    Reply
    • All I needed was my vps to open port 587 , my gmail plugin works per the debug, but my email notification on my other plugin isnt working. Thanks for the no-reply

      Reply
      • @Brad, All the information is available in the “Troubleshooting” section. It’s not always possible to guess exactly what is causing the connection error. You will need to follow it step by step.

        Reply
  7. is this work with contact form 7?

    Reply
    • @Cecep, Yes. It will work with any form that uses the wp_mail function to send an email.

      Reply
  8. How many “OAuth 2.0 client IDs” can I have on a project because currently, I have 37 client IDs on a project and anytime I try to add a new one, I get an error.

    Reply
    • @Eric, I’m not really sure. I just have one app in a project for testing this plugin

      Reply
  9. Hello,

    I got this error just now.

    Fatal error: Call to undefined function GuzzleHttpHandlercurl_reset() in /home3/boyiboyi/public_html/wp-content/plugins/gmail-smtp/google-api-php-client/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php on line 78

    What should I do?

    Thanks

    Reply
    • @Boyi, I had to update the Google API Client library today since it was conflicting with so many popular plugins. One of many changes in this version is Guzzle which is a PHP HTTP client that Google now uses to send HTTP requests. The error is actually coming from it (not the plugin). I believe it’s because there is something wrong with cURL setup on your server. Please copy and paste the content from the “Server Info” so I can take a look.

      Reply
      • I’m receiving this same :

        Server Info:
        OS: Linux a2plcpnl0352.prod.iad2.secureserver.net 2.6.32-673.26.1.lve1.4.29.el6.x86_64 #1 SMP Tue Jun 20 13:27:00 EDT 2017 x86_64
        PHP version: 5.4.45
        WordPress version: 4.8.1
        WordPress multisite: No
        openssl: Available
        allow_url_fopen: Enabled
        stream_socket_client: Available
        fsockopen: Available
        cURL: Available
        cURL Version: 7.38.0, OpenSSL/1.0.1e

        Reply
        • @Ryan, One of our users just fixed it by upgrading PHP to 5.6.

          Reply
      • Thanks for responding. As always, great plugin!

        Here is the Server Info:
        OS: Linux gator4104.hostgator.com 3.12.74-213.ELK6.x86_64 #1 SMP Tue Jun 20 00:36:01 CDT 2017 x86_64
        PHP version: 5.4.45
        WordPress version: 4.8.1
        WordPress multisite: No
        openssl: Available
        allow_url_fopen: Enabled
        stream_socket_client: Available
        fsockopen: Available
        cURL: Available
        cURL Version: 7.19.7, NSS/3.27.1

        Reply
        • @Boyi, I don’t see anything wrong with it. Could you ask your host to look into it? Upgrading PHP might help.

          Reply
          • Thanks. I have fixed it by updating the PHP version from 5.4 to 5.6 in Hostgator Cpanel.

          • @Boyi, Glad to hear that the issue is fixed now. So PHP version was the issue. Not sure why Google stated in their documentation that 5.4 is enough to run their API client library. I believe they need to update their documentation.

  10. I have the same problem:

    ( ! ) Fatal error: Uncaught GuzzleHttpExceptionRequestException: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see curl.haxx.se/libcurl/c/libcurl-errors.html) in D:softaculouswwwacoefibolsawp-contentpluginsgmail-smtpgoogle-api-php-clientvendorguzzlehttpguzzlesrcHandlerCurlFactory.php on line 187
    ( ! ) GuzzleHttpExceptionRequestException: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see curl.haxx.se/libcurl/c/libcurl-errors.html) in D:softaculouswwwacoefibolsawp-contentpluginsgmail-smtpgoogle-api-php-clientvendorguzzlehttpguzzlesrcHandlerCurlFactory.php on line 187
    Call Stack
    # Time Memory Function Location
    1 0.0830 3961248 {main}( ) …options-general.php:0
    2 0.0840 4008488 require_once( ‘D:softaculouswwwacoefibolsawp-adminadmin.php’ ) …options-general.php:10
    3 0.0840 4022552 require_once( ‘D:softaculouswwwacoefibolsawp-load.php’ ) …admin.php:31
    4 0.0850 4034440 require_once( ‘D:softaculouswwwacoefibolsawp-config.php’ ) …wp-load.php:37
    5 0.0850 4123976 require_once( ‘D:softaculouswwwacoefibolsawp-settings.php’ ) …wp-config.php:92
    6 1.1751 45621224 do_action( ) …wp-settings.php:448
    7 1.1751 45621520 WP_Hook->do_action( ) …plugin.php:453
    8 1.1751 45621544 WP_Hook->apply_filters( ) …class-wp-hook.php:323
    9 1.2911 49855712 GMAIL_SMTP->plugin_init( ) …class-wp-hook.php:298
    10 1.3041 50890768 GmailXOAuth2::resetCredentials( ) …main.php:144
    11 1.3051 50999080 Google_Client->authenticate( ) …class.phpmaileroauthgoogle.php:99
    12 1.3051 50999080 Google_Client->fetchAccessTokenWithAuthCode( ) …Client.php:170
    13 1.3181 51704712 GoogleAuthOAuth2->fetchAuthToken( ) …Client.php:191
    14 1.3221 51802744 GoogleAuthHttpHandlerGuzzle6HttpHandler->__invoke( ) …OAuth2.php:492
    15 1.3221 51802792 GuzzleHttpClient->send( ) …Guzzle6HttpHandler.php:34
    16 1.3781 51935184 GuzzleHttpPromiseRejectedPromise->wait( ) …Client.php:106

    Reply
  11. I just upgraded to version 1.1.5 of Gmail SMTP and now my emails are no longer sending. I get a warning at the top that GMail SMTP requires PHP 5.6 (which my hosting provider does not have on my server, 5.5 is the highest).

    How do I resolve this, or will I have to find another product?

    Cheers

    Reply
    • @Dave, You could download and install an older version of the plugin (1.1.2) that includes the legacy Google API Client library: https://wordpress.org/plugins/gmail-smtp/advanced/

      I had to update the Google API Client library recently since it was conflicting with so many popular plugins. Unfortunately, in this version, the Google API Client library triggers a “curl_reset()” error unless the server is running on PHP 5.6 or higher. I added that warning notice so users don’t have to troubleshoot why that error is occurring on their sites.

      Reply
  12. I recently configured the Plugin and am getting the following error when sending Test Emails…

    InvalidArgumentException thrown
    Invalid token format

    Here is the server info:
    Gmail SMTP 1.1.5
    WordPress 4.8.1
    OS: Linux xxxxxxxxx 3.13.0-76-generic #120-Ubuntu SMP Mon Jan 18 15:58:41 UTC 2016 i686
    PHP version: 7.0.22-0ubuntu0.16.04.1
    WordPress version: 4.8.1
    WordPress multisite: No
    openssl: Available
    allow_url_fopen: Enabled
    stream_socket_client: Available
    fsockopen: Available
    cURL: Available
    cURL Version: 7.47.0, OpenSSL/1.0.2g

    Please help!

    Reply
  13. 2017-09-06 08:56:19 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [205.144.171.101]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
    2017-09-06 08:56:19 Auth method requested: XOAUTH2
    2017-09-06 08:56:19 Auth methods available on the server: LOGIN,PLAIN,XOAUTH2,PLAIN-CLIENTTOKEN,OAUTHBEARER,XOAUTH
    2017-09-06 08:56:19 CLIENT -> SERVER: QUIT
    2017-09-06 08:56:19 SMTP -> get_lines(): $data is “”
    2017-09-06 08:56:19 SMTP -> get_lines(): $str is “221 2.0.0 closing connection 188sm2174727pfe.171 – gsmtp”
    2017-09-06 08:56:19 SERVER -> CLIENT: 221 2.0.0 closing connection 188sm2174727pfe.171 – gsmtp
    2017-09-06 08:56:19 Connection: closed

    Fatal error: Uncaught exception ‘InvalidArgumentException’ with message ‘Invalid token format’ in H:roothomebackslash-001wwwkainosafricawp-contentpluginsgmail-smtpgoogle-api-php-clientsrcGoogleClient.php:434 Stack trace: #0 H:roothomebackslash-001wwwkainosafricawp-contentpluginsgmail-smtpclass.phpmaileroauthgoogle.php(138): Google_Client->setAccessToken(‘{“error”:”inval…’) #1 H:roothomebackslash-001wwwkainosafricawp-contentpluginsgmail-smtpPHPMailerclass.smtp.php(470): GmailXOAuth2->getOauth64() #2 H:roothomebackslash-001wwwkainosafricawp-contentpluginsgmail-smtpclass.phpmaileroauth.php(153): SMTP->authenticate(”, ”, ‘XOAUTH2’, ”, ”, Object(GmailXOAuth2)) #3 H:roothomebackslash-001wwwkainosafricawp-contentpluginsgmail-smtpPHPMailerclass.phpmailer.php(1540): PHPMailerOAuth->smtpConnect(Array) #4 H:roothomebackslash-001wwwkainosafricawp-contentpluginsgmail-smtpPHPMailerclass.phpmailer.php(1335): PHPMailer->smtpSend(‘Date: Wed, 6 Se…’, ‘testn’) #5 H:rooth in H:roothomebackslash-001wwwkainosafricawp-contentpluginsgmail-smtpgoogle-api-php-clientsrcGoogleClient.php on line 434

    Reply
  14. Can anyone help me with the previous error

    Reply
  15. I cant figure out what the issue is

    Reply
  16. Here are my Server Information

    OS: Windows NT WIN5101 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) i586
    PHP version: 5.6.27
    WordPress version: 4.8.1
    WordPress multisite: No
    openssl: Available
    allow_url_fopen: Enabled
    stream_socket_client: Available
    fsockopen: Available
    cURL: Available
    cURL Version: 7.50.3, OpenSSL/1.0.2j

    Reply
  17. I get 500 error after Authorized Redirect URL attached code query string in URL.
    can you please help me in this regard?

    Reply
    • @Asim, Please contact your web host to find more information on that 500 error.

      Reply
  18. Hello, can anybody help me with this problem: I’ve tried requesting new credentials, but still no luck

    400. That’s an error.

    Error: redirect_uri_mismatch

    The redirect URI in the request, http://www.cymortho.co.uk/wp-admin/options-general.php?page=gmail-smtp-settings&action=oauth_grant, does not match the ones authorized for the OAuth client. Visit https://console.developers.google.com/apis/credentials/oauthclient/899255158133-kc64969jk6g24927q1h8cuefhsl16n50.apps.googleusercontent.com?project=899255158133 to update the authorized redirect URIs.

    Sorry, not a coder, so be gentle with me!!
    Thanks
    Hugh

    Reply
    • You need to:

      * Copy/paste your “Authorized redirect URIs” in Credentals > Your OAuth 2.0
      * Credentials > Domain Verification (add your domain there)

      Reply
      • My domain already verify and also copy paste authorized redirect URIs then also same error came

        Reply
  19. In the setup window, we can enter “From Email Address”. When I test email, the OAuth email is the “from address”, not the address I entered in the “From Email Address” field.

    What am I doing wrong?

    Reply
  20. Hello. I have this error, can’t find what to do.
    Fatal error: Uncaught exception ‘InvalidArgumentException’ with message ‘Invalid token format’ in /wp-content/plugins/gmail-smtp/google-api-php-client/src/Google/Client.php:434 Stack trace: #0 /wp-content/plugins/gmail-smtp/class.phpmaileroauthgoogle.php(138): Google_Client->setAccessToken(‘{“error”:”inval…’) #1 /wp-content/plugins/gmail-smtp/PHPMailer/class.smtp.php(470): GmailXOAuth2->getOauth64() #2 /wp-content/plugins/gmail-smtp/class.phpmaileroauth.php(153): SMTP->authenticate(”, ”, ‘XOAUTH2’, ”, ”, Object(GmailXOAuth2)) #3 /wp-content/plugins/gmail-smtp/PHPMailer/class.phpmailer.php(1540): PHPMailerOAuth->smtpConnect(Array) #4 /wp-content/plugins/gmail-smtp/PHPMailer/class.phpmailer.php(1335): PHPMailer->smtpSend(‘Date: Tue, 12 S…’, ‘testn’) #5 /wp-content/plugins/gmail-smtp/PHPMailer/class.phpmailer.php(1213): PHPMailer->postSend() #6 /wp-content/plugins/gmail-smtp/main.php(943): PHPMailer->send() #7 /wp-content/plugins/gmail-smtp/main.php(183): wp_mail(‘gosia@asiandive…’, ‘test 5’, ‘test’) #8 /wp-conten in /wp-content/plugins/gmail-smtp/google-api-php-client/src/Google/Client.php on line 434

    Reply

Leave a Comment