在我配置邮件通知时，用了很多插件都不行，主机商 php mail 函数发不了，25 , 465 , 587 这些 smtp 端口也被封了。也试过 maigun ，sendgird 这些用 api 的，发现 qq 邮箱会直接拒收，估计是滥用的人太多，qq 邮箱直接黑名单了。
这次用的插件是 Post SMTP ，在后台搜索安装。使用很不错，可以帮你检测你用什么最好
先来一个 Connectivity Test 看看连接情况
果然端口全部被封了，只能通过 api 方式发信，上面也说了 maigun ，sendgird 这些用 api 的，发现 qq 邮箱会直接拒收，所以不考虑这两个。
点击 Show All Settings 发现有个 gmail api 的方式。使用后发现这个没有被拒，发信也很快。
关于如何获得 Client ID 和 Client Secret 可以看下面介绍，我从官方 FAQ 复制的，按下面步骤操作即可。
- Go to Google Developer’s Console and login with the same email address that you are configuring Post with.
- Choose ‘Create a New Project’. This project will be for Post SMTP only.
- Select ‘Consent Screen’ from under ‘APIs & auth’. Into ‘Email address’ choose the correct Gmail address and in ‘Product name’ put ‘Post SMTP’. Choose ‘Save’.
- Select ‘Credentials’ from under ‘APIs & auth’. Choose ‘Create a new Client ID’.
- For the ‘Application Type’ use ‘Web application’.
- In ‘Authorized Redirect URIs’ enter the ‘Redirect URI’ given by Post (either from the wizard[screenshot], or from the manual configuration page[screenshot]).
- Choose ‘Create Client ID’.
- Enter the Client ID and Client Secret displayed here into Post’s settings page screenshot.
如果不理解还有一个视频教程，由于在 youtube 上的缘故，我自己下载后上传到了微博视频，需要看视频的点这里。
To get the Client ID and the Client Secret. Visit this URL and log in to your Gmail Account if asked.
Select Create Project and then Continue.
After a few seconds, the next screen will appear, select Go to credentials.
Skip the current screen by clicking Client ID like the image below.
In this step, you will need to name your project, press the button on the right.
Enter the Email address, fill product field and then Save.
On the Create credentials drop-down, select OAuth client ID.
Select Web application, name your app and then copy the fields. I marked from the one with the same colors from the step number 8.
Now, copy the Client ID and Client Secret from above and paste them in their respective fields on step number 8 and save.
Now from the page of Post SMTP under actions, select Grant permission with Google.
From the dialog box, select the Gmail account you want to use sending emails.
Approve the APP Name you used to send emails.
To verify you configured everything correctly, just check that your status matches this one.
The last step is to use Send a Test Email option to verify that everything is working as expected.
Enter the destination email, if everything is configured properly, you should get a report like this one.
有个地方提醒下，设置好后，需要同意调用 gmail 邮箱发信，有时会提示不是安全链接，不管继续，点击同意即可。
第二篇图文教程，我是按着这个第二篇获取的 id 和 secret。
Create a Web Application
To create an application, you’ll first need to sign into your Gmail account and access Gmail’s application registration. Clicking that link should open this Google page in a new tab or window, and you’ll want to keep your site settings open (we’ll return to those later).
Once you’ve followed that link and logged into your Gmail account, you should see a form named “Register your application for Gmail API in Google API Console”.
In the dropdown labeled Select a project where your application will be registered, leave the default option of Create a project. Then, go ahead and click the Continue button.
Next, you should see a screen that says “The API is enabled”. To proceed to the setup page, click the Go to credentials button.
In the next page, you’ll be prompted to determine the credentials you need. Here are the fields on this page and the options you’ll need to select:
- Which API are you using? Gmail API
- Where will you be calling the API from? Web server (e.g. node.js, Tomcat)
- What data will you be accessing? User data
Once you’ve made these selections, click the What credentials do I need? button to go to the next step.
For this step, you’ll be creating an OAuth client ID. OAuth, or Open Authorization, is what will provide permission for your website to use your Gmail account to authenticate emails.
For the Name field, enter anything you like or leave the default name. This is only for reference within your Google account.
Last, we need to fill out the Authorized redirect URIs field. To get the URI for your site, you’ll need to go back to the tab or window with your WordPress site. Still on the Settings » WP Mail SMTP page, you’ll need to look under the Gmail section for the field labeled Authorized redirect URI.
The value in this field should be your site’s URL followed by some extra details. You’ll need to copy this value, which is easily done by clicking the button with the copy icon.
After copying the URI, return to the Google APIs page and paste it into the field under Authorized redirect URIs.
After that, you can click the Create client ID button.
For the last step in the app creation process, you’ll need to set up the consent screen. This screen will never be seen by your users since you’re only granting permission for your own site to use the Gmail account you own.
You’ll just need to check your email address and then enter a Product name shown to users (such as the title of your website). When you’ve completed these fields, click Continue.
You’ve now successfully created a Gmail web application!
Now we need to see the full details. On the last screen, click I’ll do this later to go to the Credentials page.
Grant Permissions and Send Test Email
On the Credentials page, you can now see the details of the web application you just created. To view Client ID and Client Secret, click the edit icon.
This will open all of the details for your app. On this page, you’ll need to copy the Client ID and Client secret values.
设置好后，需要同意调用 gmail 邮箱发信，有时会提示不是安全链接，不管继续，点击同意即可。