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 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)
- Go to Plugins->Add New from your WordPress admin dashboard
- Search for “gmail smtp naa986”
- Click Install once you have found it
Option 2 (Manual install)
- Download the zip version of the plugin
- Go to Plugins->Add New
- Click Upload Plugin
- Select the zip file on your computer
- Install it
Gmail SMTP Configuration
In order to get started with the plugin go to Settings->Gmail SMTP from your admin dashboard.
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.
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.
3. Choose how you want to configure and register your app. Since I’m not using G Suite I had to choose External.
4. Enter a name (e.g. Gmail SMTP) for the OAuth consent screen.
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.
6. Skip the Scopes screen.
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).
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
I’ve used in the past But I deleted the plugin And I installed your.
I followed your instructions, In addition I allow less secure apps
But I keep getting this message
@D, you don’t need to allow less secure apps if you use this plugin.
So what causes this problem?!
@D, I’m not sure. I haven’t really encountered this error. So you have done all of these from the beginning?
1) Create an application in your Google Developers Console with the “Authorized Redirect URL” set to the one shown in the settings
2) Copy and paste the Client ID and Secret key from your App
3) Fill out the rest of the settings (OAuth email address, From email address, From name, Type of encryption, SMTP Port)
4) Save changes and then Grant permission to your App
Can you please copy and paste the details from the “Server Info” tab?
Hi, I have custom form HTML made in wordpress. Is there a way that I can integrate to GMAIL SMTP Plugin?
@Michael, If your form calls the “wp_mail” function to send an email, it should work.
Hi i like ur pluging and could connect into application, but when i test to send me an email i got this error:
Connection: opening to ssl://smtp.gmail.com:25, timeout=300, options=array ()
SMTP ERROR: Failed to connect to server: Connection refused (111)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
any ideas how to fix that?
@Fernando, Can you please try TLS on port 587 first and then SSL on port 465? Port 25 is not very reliable as most servers don’t support encryption on port 25. Please also copy and paste the content from your “Server Info” tab so I can take a look.
Hi
Im using google apps for work and have my own domain.
I have checked MX records and they are set as googles mx records
But still doesnt send test email
error message :
Connection: opening to smtp.gmail.com:587, timeout=300, options=array ()
SMTP ERROR: Failed to connect to server: Connection refused (111)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Server info:
OS: Linux p3nlwpweb380.prod.phx3.secureserver.net 2.6.32-604.30.3.lve1.3.63.el6.nfsfixes.x86_64 #1 SMP Mon Oct 26 11:56:49 MST 2015 x86_64
PHP version: 5.4.42
WordPress version: 4.4.2
WordPress multisite: No
openssl: Available
allow_url_fopen: Enabled
stream_socket_client: Available
fsockopen: Available
what am i doing wrong here?
Hi, I use my business domain for my email address, but it’s through Gmail’s Google Apps. Can I only use a true gmail.com address to use this plugin?
I’m also using a staging site on a subdomain to test this plugin (staging1.mydomain.com). I got 400 error: redirect_uir_mismatch, but the URLs match in the Developer’s site and the plugin settings.
@DM, Regarding your questions,
1. Can I only use a true gmail.com address to use this plugin? – Yes
2. I got 400 error: redirect_uir_mismatch, but the URLs match in the Developer’s site and the plugin settings.
– Please delete the existing app and create a new one. A few users have experienced the same issue recently.
Dear admin. On february 7, 2016 a user Muqeet sent an issue. I got the same. This is my “server info” tab:
OS: Linux host.chamlaty.com 2.6.32-504.1.3.el6.x86_64 #1 SMP Tue Nov 11 17:57:25 UTC 2014 x86_64
PHP version: 5.3.29 (PHPMailer requires PHP 5.4 or later in order to send email)
WordPress version: 4.4.2
WordPress multisite: No
openssl: Available
allow_url_fopen: Enabled
stream_socket_client: Available
fsockopen: Available
Thanxs 4 the help
My error is:
Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'Error fetching OAuth2 access token, message: 'invalid_client'' in /home/ppsotoas/public_html/wp-content/plugins/gmail-smtp/google-api-php-client/src/Google/Auth/OAuth2.php:125 Stack trace: #0 /home/ppsotoas/public_html/wp-content/plugins/gmail-smtp/google-api-php-client/src/Google/Client.php(128): Google_Auth_OAuth2->authenticate('4/y6JiIhp1nbGk0...', false) #1 /home/ppsotoas/public_html/wp-content/plugins/gmail-smtp/class.phpmaileroauthgoogle.php(99): Google_Client->authenticate('4/y6JiIhp1nbGk0...') #2 /home/ppsotoas/public_html/wp-content/plugins/gmail-smtp/main.php(132): GmailXOAuth2::resetCredentials('4/y6JiIhp1nbGk0...') #3 [internal function]: GMAIL_SMTP->plugin_init('') #4 /home/ppsotoas/public_html/wp-includes/plugin.php(525): call_user_func_array(Array, Array) #5 /home/ppsotoas/public_html/wp-settings.php(392): do_action('init') #6 /home/ppsotoas/public_html/wp-config.php(179): require_once('/home/ppsotoas/...') #7 /home/ppsotoas/public_html/w in /home/ppsotoas/public_html/wp-content/plugins/gmail-smtp/google-api-php-client/src/Google/Auth/OAuth2.php on line 125
Thanks for the plugin. I’ve set it up and it’s working for me, but there is a delay of around 20-40 seconds when it sends the email. I’ve tried switching to SSL and switching ports, but it doesn’t seem to make any difference in the delay. I’m on an AWS EC2 instance. If you’re able to point me in the right direction for any debugging it would be much appreciated.
@Chris, A few users have experienced this issue as well. I’m not sure if it’s caused by a delay in the server communication. Have you tried setting up Gmail SMTP using my other plugin?
https://wphowto.net/smtp-mailer-plugin-for-wordpress-1482
Please note that you will need to allow “Less secure apps” in your Gmail account to use this plugin.
Hey… thanks. I tried setting up your other plugin and enabling the less secure apps in gmail, and it works, but I’m still getting the delay (although it does seem to be a little less delay with standard auth). I’m going to change my approach. At the moment I have a loop that sends around 5 emails. Does it re-authenticate each time? I’ll try just bcc’ing and see if it reduces the delay.
@Chris, Ok that means this is not an issue in the plugin. SMTP Mailer plugin actually uses the WordPress mail function. So you would experience similar issue even if you didn’t have a SMTP plugin.
I believe It has something to do with the cloud server. Users who reported this issue were either on a cloud server or they were using CDN (Content Delivery Network). I have found this link on AWS cloud where several users were having an issue with SMTP:
https://forums.aws.amazon.com/thread.jspa?threadID=146736
Hey mate… agreed. Definitely going to be a server issue. Thanks for the link. If I find out what’s causing it I’ll post it in here. Really appreciate your help.
I have the same issue as Vin; Are we able to use this plugin if we are using google apps for business?
SMTP Status green. Tried both TLS & SSL
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
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
I followed the steps from that link originally. And started from scratch again. I created API credentials. SMTP status is green. Already changed mx settings to remote on godaddy. Still getting connection refused. Am I missing some security settings in Google apps or something?
@Ty, I heard somewhere that GoDaddy doesn’t even allow external SMTP communication (unless you use their own SMTP server). Can you please contact them to confirm?
I believe you were correct about Godaddy and external SMTP. I ended up having to create an email address on the server just for the contact form as a temporary fix. Thanks for the response.
Nice plugin. But I have an issue with sending emails (at first trying to send a test email).
This fails: SMTP Error: Could not connect to SMTP host
I had set it up as I did before (I switched hosting provider), and before it worked.
Tried multiple ports (SSL and TLS), but doesn’t work.
Any idea?
@Stephan, Which hosting is it now? Can you please copy and paste the content from the “Server Info” tab?
OS: Linux server123.hosting2go.nl 2.6.27.29.h2go #2 SMP Tue Oct 27 13:11:20 CET 2015 i686
PHP version: 5.6.19
WordPress version: 4.4.2
WordPress multisite: No
openssl: Available
allow_url_fopen: Enabled
stream_socket_client: Available
fsockopen: Available
@Stephan, Everything looks good. Which hosting provider is it?
Oh what I forgot to mention, is that I use google apps for work. So emai is going through that way
it is hosting2go, a dutch hosting company
@Stephan, I’m not sure how that hosting company works. Do they allow external SMTP connection like Gmail?
“Gmail SMTP Plugin” and email formatting.
Hi, I have installed your plugin and set it up. Works fine, Thank you!
But from that time there is a problem with email and wp notification FORMATTING. Received emails are all in line without brakes and new lines, as it was before. It looks terrible. I also use “WP Better Emails” to make notification emails to our users nicer.
Any idea how to solve it?
@John, Gmail SMTP doesn’t format the email body. Are you sending it as plain text/HTML? Does this plugin have a visual editor (where you apply formatting) or just a simple textarea?
@admin, I found the reason. once I started using SMTP via your plugin, it didn’t output PHP_EOL line brakes as PHP mail use to.
The solution is to use old good newline characters as “n”,”r”.
The SMTP Status is “Connected”. The button is green. My MX at Bluehost is set to “Remote Mail Exchanger”.
…Yet when I try to send the test message I get the error below.
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 all the “troubleshooting” steps from the “how to” page.
That is, I have changed the SMTP port to 465 with SSL encryption.
I have also changed it to port 25 with TLS first and then SSL. I still can’t send the test email.
Any other ideas?
Btw, when I visit my Bluehost zone editor, I notice that under CName it says:
“smtp mail.mysitename.com”
Could that have something to do with it? Should “smtp” point to something at gmail instead?
@jim, Setting it from “Local” to “Remote” is not enough. I believe it will also need to point to your gmail account (Please see Doug Leslie’s comment. She was able to get it to work).