跳转到主要内容

Kinto邮件插件

项目描述

https://github.com/Kinto/kinto-emailer/actions/workflows/tests.yml/badge.svg https://img.shields.io/pypi/v/kinto-emailer.svg

kinto-emailer 当某些事件发生时发送电子邮件(例如创建新记录)。它依赖于 Pyramid Mailer 进行发送部分。

安装

pip install kinto-emailer

设置

Kinto 设置中

kinto.includes = kinto_emailer

mail.default_sender = kinto@restmail.net

# mail.host = localhost
# mail.port = 25
# mail.username = None
# mail.password = None
# mail.tls = False
# mail.queue_path = None

如果设置了 mail.queue_path,则电子邮件将存储在本地 Maildir 队列中。

有关 Pyramid Mailer 配置的更多信息,请参阅 此处

验证配置

以下命令将向指定的收件人发送一个模拟电子邮件,如果配置不正确则失败。

$ kinto-send-email config/kinto.ini testemailer@restmail.net

开发

使用模拟邮件发送器,将电子邮件文件写入磁盘

mail.debug_mailer = true

它是如何工作的?

某些信息(如监视动作或收件人列表)在集合或存储桶元数据中定义。当发生事件时,如果满足预期的条件之一,插件将发送电子邮件。

用法

集合(或存储桶)的元数据必须如下所示

{
  "kinto-emailer": {
    "hooks": [{
      "template": "Something happened!",
      "recipients": ['Security reviewers <security-reviews@mozilla.com>']
    }]
  }
}

在上面的例子中,对集合元数据或该集合中任何记录的每个动作都会触发电子邮件通知。

集合的元数据会覆盖存储桶的元数据,它们不会合并。

可选

  • subject(例如 "An action was performed"

  • sender(例如 "Kinto team <developers@kinto-storage.org>"

收件人

收件人列表可以包含

  • 电子邮件地址(例如 alice@wonderland.com"Joe Doe <jon@doe.com>"

  • 组 URI(例如 /buckets/staging/groups/reviewers

使用组 URI 时,电子邮件收件人将扩展为组成员的负责人,其外观类似于电子邮件地址(例如 ldap:peace@world.org)。

选择

可以定义多个 钩子,并基于某些条件进行过滤。例如

{
  "kinto-emailer": {
    "hooks": [{
      "resource_name": "record",
      "action": "create",
      "template": "Record created!",
      "recipients": ['Security reviewers <security-reviews@mozilla.com>']
    }, {
      "resource_name": "collection",
      "action": "updated",
      "template": "Collection updated!",
      "recipients": ["Security reviewers <security-reviews@mozilla.com>"]
    }]
  }
}

可能的过滤器包括

  • resource_namerecordcollection(默认:全部)

  • actioncreateupdatedelete(默认:全部)

  • collection_id(默认:全部)

  • record_id(默认:全部)

  • eventkinto.core.events.AfterResourceChanged(默认),或 kinto_remote_settings.signer.events.ReviewRequestedkinto_remote_settings.signer.events.ReviewApprovedkinto_remote_settings.signer.events.ReviewRejected

如果过滤器值以特殊字符 ^ 开头,则匹配将考虑过滤器值作为正则表达式。

例如,为了排除特定的 collection_id,将过滤器值设置为:^(?!normandy-recipes$)

模板

模板字符串可以包含占位符

  • bucket_id

  • id:记录或集合 id

  • user_id

  • resource_name

  • uri

  • action

  • timestamp

  • root_url

  • client_address

  • user_agent

  • settings[name]

例如

{user_id} 在 {bucket_id} 中 {action} 了一个 {resource_name}。

请参阅 Kinto 核心通知

运行测试

要运行单元测试

$ make tests

对于功能测试,在单独的终端中运行 Kinto 实例

$ make run-kinto

然后启动测试套件

$ make functional

发布

  1. https://github.com/Kinto/kinto-emailer/releases/new 上创建一个发布

  2. 创建一个新的标签 X.Y.Z在发布此版本时,此标签将从目标中创建。

  3. 生成发布说明

  4. 发布版本

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

kinto-emailer-3.0.1.tar.gz (18.4 kB 查看散列值

上传时间:

构建分布

kinto_emailer-3.0.1-py3-none-any.whl (7.5 kB 查看散列值

上传时间: Python 3

由...