# 如何禁用访问而不向用户发送电子邮件

**URL:** https://meta.discourse.org/t/how-to-disable-access-without-emailing-user/186244
**Category:** Support
**Created:** [2021年四月9日 18:03 UTC](https://meta.discourse.org/t/how-to-disable-access-without-emailing-user/186244 "2021-04-09T18:03:07Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![ryantm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ryantm/32/134063_2.png) [@ryantm](https://meta.discourse.org/u/ryantm)
#### Post date: [2021年四月9日 18:03 UTC](https://meta.discourse.org/t/how-to-disable-access-without-emailing-user/186244/1 "2021-04-09T18:03:07Z")

</div>

您好。

我的论坛版本是 2.7.0.beta6。

我负责维护一个员工论坛，我们希望在无需发送邮件通知的情况下，禁止特定用户访问。目前我们是通过暂停其账户来实现的，但暂停账户时，系统会向该用户发送一封包含暂停原因的邮件。我们实在不想因此打扰到对方。

我曾尝试先停用测试账户，然后再暂停它，但即便如此，邮件仍然会被发送。

注意：当我暂停用户时，“邮件消息”字段并未填写任何内容。

请问是否有办法在不发送邮件的情况下禁用用户对 Discourse 的访问权限？

- Ryan

---

<div class="post-metadata">

### Author: ![ryantm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ryantm/32/134063_2.png) [@ryantm](https://meta.discourse.org/u/ryantm)
#### Post date: [2021年四月9日 18:41 UTC](https://meta.discourse.org/t/how-to-disable-access-without-emailing-user/186244/2 "2021-04-09T18:41:17Z")

</div>

以下是可在 Rails 控制台中执行的代码：

```Console
./launcher enter app 
rails c

```

```Ruby
username = "user-to-suspend-username"
admin_username = "admin-username"
reason = "suspend reason"
till = Time.at(33174889200)
u = User.find_by_username(username)
puts "couldn't find user named #{username}" unless u
if u and !u.suspended?
  u.suspended_till = till
  u.suspended_at = DateTime.now

  User.transaction do
    u.save!
    admin = User.find_by_username(admin_username)
    StaffActionLogger.new(admin).log_user_suspend(
      u,
      reason
    )
  end
  u.logged_out
end

```

---

<div class="post-metadata">

### Author: ![Richie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/richie/32/115110_2.png) [@Richie](https://meta.discourse.org/u/Richie)
#### Post date: [2021年四月9日 20:45 UTC](https://meta.discourse.org/t/how-to-disable-access-without-emailing-user/186244/3 "2021-04-09T20:45:22Z")

</div>

如果该人员已不再是员工，他们为何仍能访问其企业邮箱账户？🤔

> [@ryantm](#):
>
> 我们真的不想用邮件去打扰对方。

你可以先编辑该用户，将其邮箱地址更改为 no@email.some.random.nonexistent.domain，然后再暂停其账户。

---

<div class="post-metadata">

### Author: ![ryantm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ryantm/32/134063_2.png) [@ryantm](https://meta.discourse.org/u/ryantm)
#### Post date: [2021年四月9日 20:58 UTC](https://meta.discourse.org/t/how-to-disable-access-without-emailing-user/186244/4 "2021-04-09T20:58:14Z")

</div>

> [@Richie](#):
>
> 如果该人员已不再是员工，他们为何仍能访问其企业邮箱账户？

系统使用的是个人邮箱。

> [@Richie](#):
>
> 您始终可以先编辑该用户。

我知道如何在 Rails 控制台中操作，但有没有办法在 Web 界面中完成？我看到可以在他们的个人资料中编辑邮箱，但看起来需要验证邮箱后才能生效。

---

<div class="post-metadata">

### Author: ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)
#### Post date: [2021年四月9日 21:08 UTC](https://meta.discourse.org/t/how-to-disable-access-without-emailing-user/186244/5 "2021-04-09T21:08:53Z")

</div>

之前发送邮件不是可选的吗？

---

<div class="post-metadata">

### Author: ![ryantm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ryantm/32/134063_2.png) [@ryantm](https://meta.discourse.org/u/ryantm)
#### Post date: [2021年四月9日 21:12 UTC](https://meta.discourse.org/t/how-to-disable-access-without-emailing-user/186244/6 "2021-04-09T21:12:51Z")

</div>

所有文档都表明情况确实如此！但是，即使你留空消息部分，它仍然会发送邮件。

> **[Discourse API Docs](https://docs.discourse.org/#tag/Users/paths/~1admin~1users~1%7Bid%7D~1suspend.json/put)**

> 当存在此消息时，将发送包含该消息的电子邮件

 ![image](https://global.discourse-cdn.com/meta/original/3X/0/a/0a315e858ea09b568759e03acfeda5e4acf6337f.png)

> 可选地，提供有关停用的更多信息，该信息将被电子邮件发送给用户。

---

<div class="post-metadata">

### Author: ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)
#### Post date: [2021年四月9日 21:15 UTC](https://meta.discourse.org/t/how-to-disable-access-without-emailing-user/186244/7 "2021-04-09T21:15:03Z")

</div>

你说得对，我刚刚测试过了。而且，停用用户的邮箱也无法阻止邮件发送。我敢肯定，在以前的版本中，除非添加了可选消息，否则不会发送邮件。

---

<div class="post-metadata">

### Author: ![ryantm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ryantm/32/134063_2.png) [@ryantm](https://meta.discourse.org/u/ryantm)
#### Post date: [2021年四月9日 21:20 UTC](https://meta.discourse.org/t/how-to-disable-access-without-emailing-user/186244/8 "2021-04-09T21:20:55Z")

</div>

我已发起一个拉取请求，以使行为与文档保持一致：

> <https://github.com/discourse/discourse/pull/12666>
>
> This makes behavior consistent with documentation:
> 
> API:
> 
> \> Will send an ema…il with this message when present
> 
> Web UI:
> 
> \> Optionally, provide more information about the suspension and it will be emailed to the user

---

<div class="post-metadata">

### Author: ![ryantm](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ryantm/32/134063_2.png) [@ryantm](https://meta.discourse.org/u/ryantm)
#### Post date: [2021年四月12日 16:33 UTC](https://meta.discourse.org/t/how-to-disable-access-without-emailing-user/186244/9 "2021-04-12T16:33:16Z")

</div>

此修复已由 @eviltrout 合并 🎉

---

<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: [2021年五月12日 16:33 UTC](https://meta.discourse.org/t/how-to-disable-access-without-emailing-user/186244/10 "2021-05-12T16:33:29Z")

</div>

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