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. I have installed the plugin and followed the setup instructions but it does not work. It shows it is connected, but I get this message….

    “Connection: opening to smtp.gmail.com:587, timeout=300, options=array ()
    SMTP ERROR: Failed to connect to server: Network is unreachable (101)
    SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
    Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

    I have tried changing the ports like you suggested but still no difference. Ideas?

    Reply
    • @Doug, Did you try all the ports with SSL? Please copy and paste content from the “Server Info” tab so I can take a look (Settings->Gmail SMTP->Server Info).

      Reply
  2. Here is onfo for you of the “server info” tab…..

    OS: Linux box541.bluehost.com 3.12.50-39.ELK6.x86_64 #1 SMP Mon Nov 2 03:10:26 CST 2015 x86_64
    PHP version: 5.4.43
    WordPress version: 4.4
    WordPress multisite: No
    openssl: Available
    allow_url_fopen: Enabled
    stream_socket_client: Available
    fsockopen: Available

    Reply
    • @Doug, Thanks. Everything looks good. So bluehost might be doing something on their end.

      Have you tried SSL encryption with all the ports (587, 465 and 25)?

      Reply
      • Yes, I have tried all the ports and still the same response. I called Blue Host prior to contacting you and they said since my MX records point to Gmail that there is nothing they can do. Any ideas?

        Reply
        • @Doug, Well, This is probably why it’s not being able to connect to the external SMTP server. This plugin doesn’t change any MX record. In fact, it doesn’t change any of your server or domain configuration. When an email is being sent via WordPress it just tells it to go through the Gmail SMTP server (all these things happen dynamically).

          Can you please ask to them to see if any SMTP plugin can be installed to send email from your bluehost server?

          Reply
          • Okay, will do . I thought this is what your plugin did – allowed me to send my contact form email through my Gmail for Work account. i will contact BlueHost again.

          • @Doug, You can. But if bluehost has some restrictions in place to block connection to the external SMTP server, the plugin can’t really do anything about it.

          • Okay. Thank you. I may have figured it out on the BlueHost side via a setting in the Zone Editor. Thank you for your help.

          • @Doug, You’re welcome. Feel free to share once you have found a solution.

          • It now works. All I had to do was log into my BlueHost account and change the MX record from ‘local’ to ‘Remote’. Just tested it and everything works.

          • @Doug, Glad to hear that it’s working now 🙂

        • Hey Doug! Grappling with these same issues you were dealing with 6 months ago. May I ask if you have a dedicated IP addr through BlueHost or shared? We are using a shared hosting plan and getting 405s on sending the test e-mail.

          Reply
  3. I have encountered a much serious problem- the emails @silverliningconsultants.net are not working at all!

    Reply
    • @Salman, It needs to be a gmail address.

      Reply
  4. Hi,

    I couldn’t get this plug-in to work, so revoked it in order to try another one, which didn’t work either. I’ve now read the advice about changing the MX record to ‘remote’, which I’ve done, and I’d like to try Gmail SMTP again. However, the Grant Permission button has disappeared, so I can’t do this. I’ve uninstalled the plugin, reinstalled it and started the setup process again, but still no Grant Permission button, so I can’t make the final connection. Could you help?

    Thanks, Pete

    Reply
    • @Pete, It’s likely the access key didn’t reset. Click the “Revoke Access” button and go back to the main tab to see if it appears again.

      Reply
  5. Thanks, I’ll try that.
    Pete

    Reply
  6. excuse , do you support Chinese words . because the subject of email is scramble . it is not readable .

    TKS

    Reply
    • @evan, Is the charset of your site set to “UTF-8”? If so it should work.

      Reply
  7. Hello,

    After trying several time, I finally make it work 🙂
    (restarting from scratch is a good option)

    BUT !
    I don’t have any email that show the good “From Email Address”. All email are sent from the Gmail account (the Reply-to is also the Gmail address) which I really don’t want.

    I have several plugins where I could change the From address (Paid Memberships Pro, Theme My Login, WooCommerce) but no one are using the correct email from address.

    BTW, I choose to use your plugin because for a reason unknown, my wordpress website stop to send emails (worked before since 6 months).

    Thanks in advance

    Reply
    • @jihes, I’m glad to hear that you got it to work. For security reasons, Gmail doesn’t allow you to set a different “From Email Address” at the moment. I have this option in the plugin in case they change it in the future.

      Reply
  8. I copied the URL from “Authorized redirect URIs” into the appropriate box at the google developers console, but it didn’t work. I copied the URL from the error page, and it works fine… The difference between the two URLs is “amp;”.

    /wp-admin/options-general.php?page=gmail-smtp-settings&action=oauth_grant
    /wp-admin/options-general.php?page=gmail-smtp-settings&action=oauth_grant (added a space so “& amp” displays.)

    OS: Linux 3.2.0-4-686-pae #1 SMP Debian 3.2.68-1+deb7u6 i686
    PHP version: 5.5.30-1~dotdeb+7.1
    WordPress version: 4.4

    Thanks for the plugin!

    Reply
    • @james, Which one actually worked? The one with & or & amp;?

      Reply
      • the one with & amp ;

        Reply
        • @James, It seems Google has changed the user interface in the Developers Console area. However, the functionality is still the same. I just did a clean setup of the plugin (project creation, permission granting etc). Everything is working fine on my end.

          Reply
  9. I am having trouble too!

    It says it’s connected in the General settings.
    MX records on the domain set to remote

    Here’s the error I get:
    onnection: opening to smtp.gmail.com:587, timeout=300, options=array ()
    SMTP ERROR: Failed to connect to server: No route to host (113)
    SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
    Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

    And the server info:
    OS: Linux a2plcpnl0459.prod.iad2.secureserver.net 2.6.32-604.16.2.lve1.3.54.el6.x86_64 #1 SMP Mon Jul 27 11:32:29 EDT 2015 x86_64
    PHP version: 5.4.45
    WordPress version: 4.4
    WordPress multisite: No
    openssl: Available
    allow_url_fopen: Enabled
    stream_socket_client: Available
    fsockopen: Available

    Host is GoDaddy.

    Thoughts?

    Reply
  10. hi
    i installed plugin correctly and it works fine
    my wordpress site’s ip is blacklisted
    can i use this plugin to send wordpress registration email?

    Reply
    • @Farhad, You will need to use a SMTP server in order to send email using this plugin. Registration emails are sent by WordPress, so I don’t think you can use it for this functionality.

      Reply
  11. I’ve done all the steps correctly, and my SMTP status is currently “connected”, yet when I try to send email on WordPress or try the test email tab, I receive the error:
    SERVER -> CLIENT: 535-5.7.8 Username and Password not accepted. Learn more at535 5.7.8 https://support.google.com/mail/answer/14257 ry1sm1354093pab.30 – gsmtp
    SMTP ERROR: QUIT command failed: 535-5.7.8 Username and Password not accepted. Learn more at535 5.7.8 https://support.google.com/mail/answer/14257 ry1sm1354093pab.30 – gsmtp
    Connection: closed
    SMTP connect() failed.

    My email address is setup the same as in the Console.
    Any help would be great. Thanks

    Reply
    • @Graham, This plugin doesn’t really send any username and password to the Gmail server. So I’m not sure how you are getting this error. Do you have any other SMTP plugin installed?

      Reply
      • Hello I’m having this issue too – any fixes available?

        Reply
        • @Yiota, What issue are you having?

          Reply
  12. I followed your instructions but got the error
    as
    “”400. That’s an error.

    Error: redirect_uri_mismatch

    Application: Gmail SMTP

    You can email the developer of this application at: ifsnconferences@gmail.com

    The redirect URI in the request: http://icm2016.ifsnbzu.com/wp-admin/options-general.php?page=gmail-smtp-settings&action=oauth_grant did not match a registered redirect URI.””

    Please tell me what I do

    Reply
    • @Muqeet, Are these two URLs the same?

      1) URL shown in the plugin settings
      2) URL that you have specified in your web application

      Reply
  13. Thanks for your Kind Response, but another bad Day
    I Got this ERROR
    Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'Error refreshing the OAuth2 token, message: '{ "error" : "invalid_grant", "error_description" : "Token has been revoked." }'' in /home/foodscie/public_html/icm2016/wp-content/plugins/gmail-smtp/google-api-php-client/src/Google/Auth/OAuth2.php:363 Stack trace: #0 /home/foodscie/public_html/icm2016/wp-content/plugins/gmail-smtp/google-api-php-client/src/Google/Auth/OAuth2.php(278): Google_Auth_OAuth2->refreshTokenRequest(Array) #1 /home/foodscie/public_html/icm2016/wp-content/plugins/gmail-smtp/google-api-php-client/src/Google/Client.php(457): Google_Auth_OAuth2->refreshToken('1/4tUBZnTnwKWoI...') #2 /home/foodscie/public_html/icm2016/wp-content/plugins/gmail-smtp/class.phpmaileroauthgoogle.php(142): Google_Client->refreshToken('1/4tUBZnTnwKWoI...') #3 /home/foodscie/public_html/icm2016/wp-content/plugins/gmail-smtp/PHPMailer/class.smtp.php(446): GmailXOAuth2->getOauth64() #4 /home/foodscie/public_html/icm2016/wp-content/plugins/gmail-smtp/class.phpma in /home/foodscie/public_html/icm2016/wp-content/plugins/gmail-smtp/google-api-php-client/src/Google/Auth/OAuth2.php on line 363

    Reply
    • @Muqeet, I’m not sure what’s causing this issue. Did you delete the app accidentally? If not remove the access key and do a fresh setup. Check the “Removing Access From the Application” section for more information.

      Reply
  14. I even create a new app after revoking old one, but again got the fatal error
    Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'Error fetching OAuth2 access token, message: 'invalid_grant: Invalid code.'' in /home/foodscie/public_html/icm2016/wp-content/plugins/gmail-smtp/google-api-php-client/src/Google/Auth/OAuth2.php:125 Stack trace: #0 /home/foodscie/public_html/icm2016/wp-content/plugins/gmail-smtp/google-api-php-client/src/Google/Client.php(128): Google_Auth_OAuth2->authenticate('4/XIT9ERq2xKFvF...', false) #1 /home/foodscie/public_html/icm2016/wp-content/plugins/gmail-smtp/class.phpmaileroauthgoogle.php(99): Google_Client->authenticate('4/XIT9ERq2xKFvF...') #2 /home/foodscie/public_html/icm2016/wp-content/plugins/gmail-smtp/main.php(132): GmailXOAuth2::resetCredentials('4/XIT9ERq2xKFvF...') #3 [internal function]: GMAIL_SMTP->plugin_init('') #4 /home/foodscie/public_html/icm2016/wp-includes/plugin.php(525): call_user_func_array(Array, Array) #5 /home/foodscie/public_html/icm2016/wp-settings.php(392): do_action('init') #6 /home/foodscie/public_html/icm2016/wp-config.php(91 in /home/foodscie/public_html/icm2016/wp-content/plugins/gmail-smtp/google-api-php-client/src/Google/Auth/OAuth2.php on line 125

    Reply
  15. I also try from another gmail account but got same error

    Reply
    • @Muqeet, Can you please copy and paste content from the “Server Info” tab?

      Reply
  16. Fantastic setup and great use of oauth.

    I’ve got the plugin install and configured, I can even send myself a test email.

    But my jetpack contact forms do not send the messages. I’ve tried both tls and ssl, both send through the test box, but not through the website form.

    Any thoughts that might spur me in the right direction?

    Reply
    • @Wes, Do you get a success message after you submit the contact form? Have you checked the spam folder?

      Reply
        • @Wes, I just tested it with Jetpack contact form on my development site. It seems to be working fine. Do you have any other plugin that sends email?

          Reply
          • I think it was my comment disabling plugin that was the culprit, I set up a new contacts plugin and it seems to be working fine.

            Thanks for your thoughts!

          • @Wes, Glad to hear that it’s working now 🙂

  17. Hello, This is the third plugin I’ve tried to get to work for our emails. This is the error message I received:

    Connection: opening to ssl://smtp.gmail.com:465, timeout=300, options=array ()
    SMTP ERROR: Failed to connect to server: Network is unreachable (101)
    SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
    Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

    Here is the server info:
    OS: Linux box741.bluehost.com 3.12.52-20160119.106.ELK6.x86_64 #1 SMP Tue Jan 19 16:53:32 CST 2016 x86_64
    PHP version: 5.6.17
    WordPress version: 4.4.2
    WordPress multisite: No
    openssl: Available
    allow_url_fopen: Enabled
    stream_socket_client: Available
    fsockopen: Available

    Our website is running on Bluehost.
    I have been working with Google tech, and just updated all the mx records on Bluehost, and updated the spx records.

    Please help. My head is spinning.

    Reply
    • @Kaylene, So you have changed the mx record from “local” to “remote”? Did you try TLS on port 587?

      Reply
  18. Admin,
    Yes the mx record is set to remote, and I tried the TLS on port 587 this morning, no change.

    I have the WP Mail Log plugin installed, and it is not showing any emails being sent from the Gmail SMTP plugin. Does that offer any clues?

    Reply
    • @Kaylene, Your server information looks good. So I’m not sure why emails are getting blocked. I know bluehost does support SMTP.

      Do you have any other email plugin installed? If so can you please deactivate them to see how it goes? I don’t know if WP Mail Log uses wp_mail function. But it’s safe to deactivate it as well.

      Reply
  19. We do not have an SSL certificate for our website. Could that be the problem? Do I have to change the DNS records on our bluehost site to all point to Google? Or should they be left in the default state?

    Thank you for sticking with me on this.

    Reply
    • @Kaylene, You don’t need to have an SSL certificate installed. Your server already has the openssl extension. So that may not be the source of this issue.

      Can you please ask bluehost to see if a SMTP plugin can be configured on your site?

      Reply
  20. SMTP Error: Could not authenticate.
    CLIENT -> SERVER: QUIT
    SMTP -> get_lines(): $data is ""
    SMTP -> get_lines(): $str is "535-5.7.8 Username and Password not accepted. Learn more at"
    SMTP -> get_lines(): $data is "535-5.7.8 Username and Password not accepted. Learn more at"
    SMTP -> get_lines(): $str is "535 5.7.8 https://support.google.com/mail/answer/14257 e127sm21398775wma.20 - gsmtp"
    SERVER -> CLIENT: 535-5.7.8 Username and Password not accepted. Learn more at535 5.7.8 https://support.google.com/mail/answer/14257 e127sm21398775wma.20 - gsmtp
    SMTP ERROR: QUIT command failed: 535-5.7.8 Username and Password not accepted. Learn more at535 5.7.8 https://support.google.com/mail/answer/14257 e127sm21398775wma.20 - gsmtp
    Connection: closed
    SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
    Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshootin

    Reply
    • @D, This plugin doesn’t really authenticate with username and password. Are you using a different SMTP plugin?

      Reply

Leave a Comment