# Gmail 发送通知邮件的开发入门

**URL:** https://meta.discourse.org/t/introduction-to-development-for-notification-mail-sending-with-gmail/376772
**Category:** Development
**Tags:** docker, email, oauth2
**Created:** [2025年七月31日 19:04 UTC](https://meta.discourse.org/t/introduction-to-development-for-notification-mail-sending-with-gmail/376772 "2025-07-31T19:04:50Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Abris](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/abris/32/515215_2.png) [@Abris](https://meta.discourse.org/u/Abris)
#### Post date: [2025年七月31日 19:04 UTC](https://meta.discourse.org/t/introduction-to-development-for-notification-mail-sending-with-gmail/376772/1 "2025-07-31T19:04:50Z")

</div>

您好，

我是 Ruby 和 Docker 的新手，但之前有其他开发经验。我有一个正在运行的开发 Discourse 实例和一个生产实例，因此依赖项似乎都已满足。我想为 [no-reply@discourse.example.com](mailto:no-reply@discourse.example.com) 添加 OAuth 2.0 功能，以便通过 Google Workspace 用户发送通知。

我恳请您在以下方面提供帮助：

- 如何从 discourse git 存储库创建 docker 镜像？
- 代码的哪个部分包含 no-reply 的 STMP 身份验证以及发送通知？

如果进展顺利，我想使其可以在 ./discourse-setup 脚本中进行选择，以便在大多数邮件提供商处提供 webmaster，并在邮件提供商为 Google 时提供 OAuth 2.0。如果您觉得有用，我可以发送结果供您审查。

此致

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [2025年七月31日 19:09 UTC](https://meta.discourse.org/t/introduction-to-development-for-notification-mail-sending-with-gmail/376772/2 "2025-07-31T19:09:35Z")

</div>

你最好从这里阅读：

> [@Can Discourse ship frequent Docker images that do not need to be bootstrapped?](https://meta.discourse.org/t/can-discourse-ship-frequent-docker-images-that-do-not-need-to-be-bootstrapped/33205/184?u=merefield):
>
> Eh… I’m pondering setting up a forum/community board and obviously thought about using Discourse (because I enjoy end-user experience) but again I hit the roadblock with completely hostile installation/management… Over the years I grew super attached with having everything run with simple docker-compose file, throwing a couple of additional elements (database, minio for s3 compatible storage and whatnot) but nope… Discourse is still super hostile in this case. I’m sorry but having some silly “…

强烈建议使用标准安装

---

<div class="post-metadata">

### Author: ![Abris](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/abris/32/515215_2.png) [@Abris](https://meta.discourse.org/u/Abris)
#### Post date: [2025年七月31日 19:22 UTC](https://meta.discourse.org/t/introduction-to-development-for-notification-mail-sending-with-gmail/376772/3 "2025-07-31T19:22:31Z")

</div>

感谢您的快速回复。我将使用 `./discourse-setup` 脚本，但我需要将 discourse 设置为 OAuth 客户端，而不是 SMTP 客户端，因此我需要先将其添加到源中。我在 discourse\_docker 存储库中找不到 discourse 源。我该如何修改 discourse 源然后运行 `./discourse-setup` 脚本？如果您不建议使用 `./launcher`，我也可以不继续这个方向。

目前，我拥有 discourse 和 discourse\_docker 存储库。

---

<div class="post-metadata">

### Author: ![Abris](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/abris/32/515215_2.png) [@Abris](https://meta.discourse.org/u/Abris)
#### Post date: [2025年七月31日 19:25 UTC](https://meta.discourse.org/t/introduction-to-development-for-notification-mail-sending-with-gmail/376772/4 "2025-07-31T19:25:02Z")

</div>

是把本地仓库拉到启动器/discourse-setup 脚本而不是上游吗？

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [2025年七月31日 19:32 UTC](https://meta.discourse.org/t/introduction-to-development-for-notification-mail-sending-with-gmail/376772/5 "2025-07-31T19:32:22Z")

</div>

> [@Abris](#):
>
> 我需要将 Discourse 设置为 OAuth 客户端，而不是 SMTP 客户端

您是指使用 OAuth 身份验证而不是基本身份验证的 SMTP 吗？还是您想通过其他途径发送邮件？

Discourse 不支持 SMTP OAuth 身份验证，因此最简单的方法可能是让 Discourse 将邮件交给本地邮件服务器处理，该服务器配置为使用必要的身份验证提交邮件。

Google 支持的机制似乎是：

> **[Route outgoing SMTP relay messages through Google - Google Workspace Admin Help](https://support.google.com/a/answer/2956491?hl=en)**
>
> Set up your on-premise email server for SMTP relay through Google servers If your organization uses Microsoft Exchange or another SMTP service or server, you can set up the SMTP relay servi

---

<div class="post-metadata">

### Author: ![Abris](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/abris/32/515215_2.png) [@Abris](https://meta.discourse.org/u/Abris)
#### Post date: [2025年七月31日 19:38 UTC](https://meta.discourse.org/t/introduction-to-development-for-notification-mail-sending-with-gmail/376772/6 "2025-07-31T19:38:53Z")

</div>

我的意思是，在我的情况下，Discourse 应该连接到邮件提供商的 OAuth 2，而不是 SMTP。不幸的是，我发现我的邮件在不使用大型邮件提供商时很可能被列为垃圾邮件，因此我决定为 Discourse 使用的 no-reply 帐户添加 OAuth 2 身份验证并连接到 Google Workspace。我也尝试过 Mailgun，但我也需要 IMAP 支持。

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [2025年七月31日 19:42 UTC](https://meta.discourse.org/t/introduction-to-development-for-notification-mail-sending-with-gmail/376772/7 "2025-07-31T19:42:12Z")

</div>

> [@Abris](#):
>
> 在我的情况下，Discourse 应该连接到邮件提供商的 OAuth 2，而不是 SMTP

正确的说法是：

> 我希望 Discourse 使用 oAuth2 身份验证而不是基本身份验证来连接到 SMTP 服务器

> [@Abris](#):
>
> mailgun，但我还需要 IMAP 支持

这是为了用户回复/入站邮件吗？

我了解到有一个 [mailgun 插件](https://meta.discourse.org/t/discourse-mailgun-routes/210609?u=supermathie) 可以实现此功能，但我还没有使用过。

---

<div class="post-metadata">

### Author: ![Abris](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/abris/32/515215_2.png) [@Abris](https://meta.discourse.org/u/Abris)
#### Post date: [2025年七月31日 19:43 UTC](https://meta.discourse.org/t/introduction-to-development-for-notification-mail-sending-with-gmail/376772/8 "2025-07-31T19:43:53Z")

</div>

是的，这就是我想要的 🙂 我已经订阅了 Google Workspace，我想尽可能地充分利用它。

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [2025年七月31日 19:57 UTC](https://meta.discourse.org/t/introduction-to-development-for-notification-mail-sending-with-gmail/376772/9 "2025-07-31T19:57:33Z")

</div>

Google Workspace 并非为事务性电子邮件而设计。您需要使用其他工具。

如果您希望论坛接收邮件，请参阅 [为使用 Mail-Receiver 的自托管网站配置直接投递入站电子邮件](https://meta.discourse.org/t/configure-direct-delivery-incoming-email-for-self-hosted-sites-with-mail-receiver/49487)

通常，您会配置一个事务性邮件服务，从 `noreply@forum.example.com` 发送邮件，邮件接收器会接收发送给它的邮件并将其转交给 Discourse。

---

<div class="post-metadata">

### Author: ![Abris](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/abris/32/515215_2.png) [@Abris](https://meta.discourse.org/u/Abris)
#### Post date: [2025年七月31日 20:29 UTC](https://meta.discourse.org/t/introduction-to-development-for-notification-mail-sending-with-gmail/376772/10 "2025-07-31T20:29:02Z")

</div>

非常感谢，我现在就试试。

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [2025年八月30日 20:29 UTC](https://meta.discourse.org/t/introduction-to-development-for-notification-mail-sending-with-gmail/376772/11 "2025-08-30T20:29:50Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
