smtp gmail_如何使用Gmail SMTP服务器在WordPress中发送电子邮件

smtp gmail

Are you having trouble sending emails from your WordPress site?

您是否无法从WordPress网站发送电子邮件?

One easy way to solve this is by sending WordPress emails using the Gmail SMTP server.

解决此问题的一种简单方法是使用Gmail SMTP服务器发送WordPress电子邮件。

In this article, we will show you how to send emails from your WordPress site using the Gmail SMTP server.

在本文中,我们将向您展示如何使用Gmail SMTP服务器从WordPress网站发送电子邮件。

Using Gmail SMTP server in WordPress

为什么以及何时需要WordPress电子邮件的Gmail SMTP服务器 (Why and When You Need Gmail SMTP Server for WordPress Emails)

Your WordPress site sends emails to notify you of new user registration, lost password reset, automatic updates, and even notifications from your contact forms.

您的WordPress网站会发送电子邮件,通知您有关新用户注册密码重置丢失 ,自动更新,甚至来自联系表的通知。

By default, WordPress uses the PHP mail function to send out email notifications. However, this function doesn’t work as expected due to a number of reasons.

默认情况下,WordPress使用PHP邮件功能发送电子邮件通知。 但是,由于多种原因,此功能无法正常工作。

Most WordPress hosting companies restrict usage of this function to prevent abuse and spam.

大多数WordPress托管公司都限制使用此功能,以防止滥用和垃圾邮件。

Spam filters on popular email service providers check incoming emails to monitor if they are sent from authentic mail servers. Default WordPress emails fail this check and sometimes may not even make it to the spam folder.

流行的电子邮件服务提供商上的垃圾邮件过滤器会检查传入的电子邮件,以监视它们是否是从真实的邮件服务器发送的。 默认的WordPress电子邮件无法通过此检查,有时甚至无法进入垃圾邮件文件夹。

SMTP (Simple Mail Transfer Protocol) is the industry standard for sending emails. Unlike the PHP mail function, SMTP uses proper authentication, which increases email deliverability.

SMTP(简单邮件传输协议)是用于发送电子邮件的行业标准。 与PHP邮件功能不同,SMTP使用适当的身份验证,这可以提高电子邮件的可传递性。

Gmail provides SMTP service that you can use to send out emails from your WordPress site. If you just want to send WordPress notification emails to yourself and few users on your site, then Gmail SMTP servers are the best option.

Gmail提供了SMTP服务,您可以使用该服务从WordPress网站发送电子邮件。 如果您只想向自己和站点上的少数用户发送WordPress通知电子邮件 ,则Gmail SMTP服务器是最佳选择。

However, if you are planning on sending newsletter emails using WordPress, then you should use a mass emailing service provider, like Sendinblue or Mailgun.

但是,如果您打算使用WordPress发送时事通讯电子邮件 ,则应使用大众电子邮件服务提供商,例如Sendinblue或Mailgun。

适用于WordPress的免费vs付费Gmail SMTP服务 (Free vs Paid Gmail SMTP Service for WordPress)

You can use your free Gmail account to send out WordPress emails. However, for better deliverability, we recommend using paid G Suite.

您可以使用免费的Gmail帐户发送WordPress电子邮件。 但是,为了获得更好的可交付性,我们建议使用付费G Suite

With G Suite, you get your own professional branded email address such as (name@yoursite.com).

使用G Suite,您可以获得自己的专业品牌电子邮件地址,例如(name@yoursite.com)。

G Suite requires you to add MX records to your domain name which means that your emails will appear to be coming from your own domain name boosting authenticity and ensuring better deliverability.

G Suite要求您在域名中添加MX记录,这意味着您的电子邮件似乎来自您自己的域名,从而提高了真实性并确保了更好的传递性。

We use G Suite for WPBeginner and can honestly say it’s the best.

我们将G Suite用于WPBeginner,可以说是最好的。

如何使用Google SMTP视频教程发送电子邮件 (How to Send Email using Google SMTP Video Tutorial)

演示地址

If you prefer written instructions, then please continue reading.

如果您喜欢书面说明,请继续阅读。

如何使用Gmail SMTP服务器发送WordPress电子邮件 (How to Send WordPress Emails Using Gmail SMTP Server)

If you decided to use G Suite, then you first need to set up your domain to work with Google Apps. We have a step by step tutorial on how to set up a professional email address with G Suite.

如果您决定使用G Suite ,则首先需要设置您的域以使用Google Apps。 我们提供了有关如何使用G Suite设置专业电子邮件地址的分步教程。

The rest of the instructions are the same whether you are using a paid or free Gmail account.

无论您使用的是付费还是免费的Gmail帐户,其余说明都是相同的。

First thing you need to do is install and activate the WP Mail SMTP plugin. For more details, see our step by step guide on how to install a WordPress plugin.

您需要做的第一件事是安装并激活WP Mail SMTP插件。 有关更多详细信息,请参阅有关如何安装WordPress插件的分步指南。

WP Mail SMTP is the best WordPress SMTP plugin on the market. It allows you to easily use any SMTP server to send WordPress emails with higher deliverability.

WP Mail SMTP是市场上最好的WordPress SMTP插件。 它使您可以轻松地使用任何SMTP服务器发送具有更高可传递性的WordPress电子邮件。

We recommend buying the paid version called WP Mail SMTP Pro which gives you access to premium support, more mailers, and white-glove set up by one of their experts.

我们建议您购买名为WP Mail SMTP Pro的付费版本,该版本可让您使用高级支持,更多邮件程序以及由其专家之一设置的白手套。

Upon activation, you need to visit Settings » WP Mail SMTP page to configure the plugin settings.

激活后,您需要访问设置»WP Mail SMTP页面以配置插件设置。

WP Mail SMTP Settings

First, you need to make sure that you use your Gmail email address in the ‘From Email’ field. Next, you need to provide the sender’s name.

首先,您需要确保在“发件人电子邮件”字段中使用Gmail电子邮件地址。 接下来,您需要提供发件人的姓名。

WP Mail SMTP plugin offers two ways to connect your WordPress site to the Gmail servers.

WP Mail SMTP插件提供了两种将WordPress网站连接到Gmail服务器的方法。

The first method uses OAuth Authentication. This is a more secure method to send emails using Gmail servers.

第一种方法使用OAuth身份验证。 这是使用Gmail服务器发送电子邮件的更安全的方法。

The second method is by entering Gmail SMTP settings manually. This method is not recommended because it is less secure.

第二种方法是通过手动输入Gmail SMTP设置。 不建议使用此方法,因为它的安全性较低。

That being said, let’s set up WordPress to use Gmail SMTP for sending emails.

话虽这么说,让我们将WordPress设置为使用Gmail SMTP发送电子邮件。

方法1:设置Gmail以使用OAuth协议发送WordPress电子邮件 (Method 1: Setting up Gmail to Send WordPress Emails using OAuth Protocol)

This method is recommended for all users. It is more secure and once you set it up, you’ll never have to do that again.

建议所有用户使用此方法。 它更加安全,一旦设置好,您将无需再做一次。

You need to start by selecting Gmail as your mailer and set the return path to be the same as sender.

首先,需要选择Gmail作为邮件发件人,并将返回路径设置为与发件人相同。

Select Gmail and set return path

Next, you will see the option to enter your Client ID, Client Secret, and a URL in ‘Authorized redirect URI’ field.

接下来,您将看到在“授权重定向URI”字段中输入客户端ID,客户端密钥和URL的选项。

Let’s set up these fields.

让我们设置这些字段。

为Gmail创建应用并生成API密钥 (Creating an App and Generate API Keys for Gmail)

Visit the Google Developers Console website and create a new project.

访问Google Developers Console网站并创建一个新项目。

Create a new Google Developer Console project

If you don’t see the blue button to create a project, then you can also click on select a project drop-down and create a new project.

如果您没有看到用于创建项目的蓝色按钮,则还可以单击选择项目下拉菜单并创建一个新项目。

You’ll be asked to provide a name for your project. Give it a memorable name, so that you can easily recognize it in the future.

系统会要求您提供项目名称。 给它起一个令人难忘的名称,以便将来轻松识别它。

Name your project

After that, click on the create button to continue.

之后,单击创建按钮继续。

Developer console will now create your project and take you to its dashboard. Google offer developers access to many of their APIs and services. You need to enable the APIs that you will be needing for this project.

开发者控制台现在将创建您的项目,并将您带到其仪表板。 Google为开发人员提供了访问其许多API和服务的权限。 您需要启用该项目所需的API。

Enable APIs

Click on Enable APIs and services button to continue.

单击启用API和服务按钮继续。

This will bring you to the APIs library page. Next, you need to type Gmail in the search box to quickly find the Gmail API and click to select it.

这将带您进入API库页面。 接下来,您需要在搜索框中键入Gmail,以快速找到Gmail API,然后单击以选中它。

Select Gmail API

You will now see an overview of the API and what it can do. Simply click on the ‘Enable’ button to continue.

现在,您将看到API的概述及其功能。 只需单击“启用”按钮即可继续。

Enale Gmail API

Now that your API is enabled, the next step is to create credentials that you can use in your WP Mail SMTP plugin settings.

现在您的API已启用,下一步是创建可在WP Mail SMTP插件设置中使用的凭据。

Click on the create credentials button to continue.

单击创建凭据按钮以继续。

Create credentials

On the next screen, you will need to select ‘Web browser JavaScript’ in ‘Where you’ll be calling the API from’ field. After that click on the ‘User Data’ option.

在下一个屏幕上,您需要在“从哪里调用API的位置”字段中选择“ Web浏览器JavaScript” 。 之后,单击“用户数据”选项。

API credentials step 1

To continue, click on the ‘What credentials do I need?’ button.

要继续,请单击“我需要什么凭证?” 按钮。

You will now be asked to provide a name for your OAuth client name. You can enter ‘WP Mail SMTP’ here.

现在将要求您提供OAuth客户端名称的名称。 您可以在此处输入“ WP Mail SMTP”。

API Credentials step 2

Under JavaScript origins field, you need to add your website’s domain name. Next, you need to copy and paste the authorized redirect URL from WP Mail SMTP plugin settings.

在“ JavaScript来源”字段下,您需要添加网站的域名。 接下来,您需要从WP Mail SMTP插件设置中复制并粘贴授权的重定向URL。

After that, click on the ‘Create client ID’ button to continue.

之后,点击“创建客户端ID”按钮继续。

Next, you need to enter a name for OAuth consent screen. You can put the plugin’s name here.

接下来,您需要输入OAuth同意屏幕的名称。 您可以在此处输入插件的名称。

Ouath consent screen

After entering the details, click on the continue button and the developer console will show your client ID. You can copy and paste this in the WP Mail SMTP plugin’s settings page. However, you will still need to add your client secret key.

输入详细信息后,单击继续按钮,开发人员控制台将显示您的客户端ID。 您可以将其复制并粘贴到WP Mail SMTP插件的设置页面中。 但是,您仍然需要添加客户端密钥。

Getting your client ID

Go ahead and click on the Done button to move on.

继续并单击“完成”按钮继续。

You will now be taken to your project’s credentials page. On this page, you can see your recently created credentials listed here. You need to click on the edit icon next to your credentials to continue.

现在,您将进入项目的凭据页面。 在此页面上,您可以在这里看到您最近创建的凭证。 您需要单击凭据旁边的编辑图标以继续。

Edit credentials

This will bring you to the edit credentials page where you will be able to see your client secret key. You need to copy and paste the key in your plugin’s settings page.

这将带您进入编辑凭据页面,在此页面中您将能够看到您的客户端密钥。 您需要将密钥复制并粘贴到插件的设置页面中。

Client secret key

Return back to plugin’s settings page in your WordPress admin area. Now that you have both client ID and client secret keys, you need to click on the save settings button to continue.

返回到WordPress管理区域中插件的设置页面。 现在您已经有了客户端ID和客户端密钥,您需要单击“保存设置”按钮以继续。

Save client credentials in plugin settings

The plugin will now store your settings and reload the page. After that, you need to scroll down to the bottom of the settings page and click on the ‘Allow plugin to send emails using your Google account’ button.

插件现在将存储您的设置并重新加载页面。 之后,您需要向下滚动到设置页面的底部,然后单击“允许插件使用您的Google帐户发送电子邮件”按钮。

Allow plugin to send emails

This will take you to your account on Google, and you will be asked to give the website permission to send emails on your behalf.

这会将您带到您在Google上的帐户,并且会要求您授予网站许可以代表您发送电子邮件。

Allow Gmail

Click on the Allow button to give permissions.

单击允许按钮以授予权限。

After that, you will be redirected back to your website where you will see a success message.

之后,您将被重定向回您的网站,在此您将看到成功消息。

Connected successfully

方法2:将Gmail SMTP设置为SMTP发件人 (Method 2: Setting up Gmail SMTP as SMTP Sender)

This method allows you to manually connect to Gmail’s SMTP servers to send your WordPress emails.

通过此方法,您可以手动连接到Gmail的SMTP服务器,以发送WordPress电子邮件。

First, you need to visit Settings » WP Mail SMTP page to configure the plugin settings.

首先,您需要访问设置»WP Mail SMTP页面来配置插件设置。

You need to start by providing the Gmail address you want to use in the ‘From Email’ field, and your name in the From ‘Name’ field.

首先,您需要在“发件人”字段中提供要使用的Gmail地址,并在“发件人名称”字段中提供您的姓名。

Gmail SMTP

Next, you need to select ‘Other SMTP’ as your mailer and check the box next to return path.

接下来,您需要选择“其他SMTP”作为您的邮件,并选中返回路径旁边的框。

After that, scroll down to the Other SMTP section to configure more settings.

之后,向下滚动到“其他SMTP”部分以配置更多设置。

Gmail SMTP settings for WP Mail SMTP plugin

Here is the exact configuration you need to add in the plugin settings:

这是您需要在插件设置中添加的确切配置:

  • SMTP Host: smtp.gmail.com

    SMTP主机:smtp.gmail.com
  • SMTP Port: 465

    SMTP端口:465
  • Encryption: Use SSL encryption

    加密:使用SSL加密
  • Authentication: Turn on authentication

    身份验证:打开身份验证
  • Username: Your complete Gmail address, e.g. john.smith@yourdomain.com or john.smith@gmail.com

    用户名:您的完整Gmail地址,例如john.smith@yourdomain.com或john.smith@gmail.com
  • Password: Password of your Gmail account

    密码:您的Gmail帐户的密码

Once you are done, click on the save changes button to store your settings.

完成后,单击保存更改按钮以存储您的设置。

That’s all, you have successfully set up WP Mail SMTP to use Gmail SMTP servers.

就是这样,您已经成功设置了WP Mail SMTP以使用Gmail SMTP服务器。

Note: If you use method two, please know that it’s less secure because your password is stored in text. You can enhance this by using the constants tip, but we strongly recommend using Method 1.

注意:如果您使用方法二,请注意它的安全性较低,因为您的密码以文本形式存储。 您可以使用常量tip来增强此效果,但是我们强烈建议您使用方法1。

测试您的WP Mail SMTP设置 (Testing Your WP Mail SMTP Settings)

WP Mail SMTP plugin allows you to test your email settings, so you can make sure that everything is working properly.

WP Mail SMTP插件允许您测试电子邮件设置,因此可以确保一切正常。

You need to visit Settings » WP Mail SMTP page and click on the ‘Email Test’ tab. Simply provide an email address that you can access in the send to field and click on the send email button.

您需要访问设置»WP Mail SMTP页面,然后单击“电子邮件测试”选项卡。 只需提供一个电子邮件地址,您可以在“发送到”字段中访问该电子邮件地址,然后单击“发送电子邮件”按钮。

Send test email

You will see a success message. You can now check your inbox to see a message with the subject line ‘WP Mail SMTP: Test Email to…’.

您将看到一条成功消息。 现在,您可以检查收件箱以查看主题为“ WP Mail SMTP:Test Email to ...”的消息。

That’s all, you have successfully setup your WordPress site to send emails using Gmail SMTP servers.

就是这样,您已经成功设置了WordPress网站以使用Gmail SMTP服务器发送电子邮件。

使用WP Mail SMTP Pro获得更多 (Get More With WP Mail SMTP Pro)

If you want even more functionality, you should try WP Mail SMTP Pro.

如果您想要更多功能,则应尝试WP Mail SMTP Pro

With the Pro version of the plugin, you can connect with:

使用该插件的专业版,您可以连接:

  • G Suite/Gmail

    G Suite / Gmail
  • Amazon SES

    亚马逊SES
  • Mailgun

    Mailgun
  • Office 365 / Outlook.com

    Office 365 / Outlook.com
  • SendGrid

    SendGrid
  • And more

    和更多

You also get additional features like email logs, ability to fine-tune / control which notification your WordPress site sends, and more.

您还将获得其他功能,例如电子邮件日志,微调/控制WordPress网站发送的通知的功能等。

对Gmail SMTP无法正常工作进行故障排除 (Troubleshooting Gmail SMTP Not Working Issues)

We have seen users encounter few issues when using Gmail SMTP with certain shared hosting configurations.

我们已经看到,在将Gmail SMTP与某些共享托管配置一起使用时,用户遇到的问题很少。

Take the following steps to fix the Gmail SMTP issue:

请按照以下步骤解决Gmail SMTP问题:

  1. Log in to your cPanel account and create an email account that matches your Google apps email address. This might seem strange because you’re not using your server for emails. This step basically tricks your server into believing that you’re sending the email through the server.

    登录到您的cPanel帐户并创建一个与您的Google Apps电子邮件地址匹配的电子邮件帐户。 这似乎很奇怪,因为您没有将服务器用于电子邮件。 此步骤基本上会欺骗您的服务器,使您相信您正在通过服务器发送电子邮件。
  2. In your cPanel account, go to the MX Records and change the MX routing from automatic to remote. It might be a little tricky to find since each host now has a custom cPanel interface. You need to look for a small link next to MX that says Email Routing: Remote Mail Exchanger.

    在您的cPanel帐户中,转到MX记录,然后将MX路由从自动更改为远程。 由于每个主机现在都有一个自定义的cPanel接口,因此查找起来可能有些棘手。 您需要在MX旁边查找一个小链接,该链接显示“电子邮件路由:远程邮件交换器”。
  3. After that log back into your WordPress site and send a test email.

    之后,登录到您的WordPress网站并发送测试电子邮件。

We hope this article helped you learn how to send email in WordPress using the Gmail SMTP server. You may also want to see our list of the best contact form plugins for WordPress, and our comparison of the best email marketing services for small business.

我们希望本文能帮助您学习如何使用Gmail SMTP服务器在WordPress中发送电子邮件。 您可能还希望查看我们的WordPress最佳联系表单插件列表,以及针对小型企业的最佳电子邮件营销服务的比较。

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

如果您喜欢这篇文章,请订阅我们的YouTube频道 WordPress视频教程。 您也可以在TwitterFacebook上找到我们。

翻译自: https://www.wpbeginner.com/plugins/how-to-send-email-in-wordpress-using-the-gmail-smtp-server/

smtp gmail

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
©️2021 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值