Kinto邮件插件
项目描述
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_name: record 或 collection(默认:全部)
action: create、update、delete(默认:全部)
collection_id(默认:全部)
record_id(默认:全部)
event: kinto.core.events.AfterResourceChanged(默认),或 kinto_remote_settings.signer.events.ReviewRequested、kinto_remote_settings.signer.events.ReviewApproved、kinto_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
发布
在 https://github.com/Kinto/kinto-emailer/releases/new 上创建一个发布
创建一个新的标签 X.Y.Z (在发布此版本时,此标签将从目标中创建。)
生成发布说明
发布版本
项目详情
kinto-emailer-3.0.1.tar.gz 的散列值
算法 | 散列摘要 | |
---|---|---|
SHA256 | 3d565b81c869cb15e5793537e9ddb0a282a2d8c3493d88ab1d5e6b05f9e26f3e |
|
MD5 | 04c80e18106865c71508dbd8b6614743 |
|
BLAKE2b-256 | 9c7e4a3236fc21179fb01181fe75654d3474d3e56147ef82ef7f5fa071af3881 |
kinto_emailer-3.0.1-py3-none-any.whl 的散列值
算法 | 散列摘要 | |
---|---|---|
SHA256 | e3d481751cbc5971eb077766691f9a2d6166b5c78964442d90273223ad1ece53 |
|
MD5 | c05e20877d19193964c322e866ae820f |
|
BLAKE2b-256 | b23371d13f38be23cfcaa63a67319e8768df657479a246a0b7457d8cee10d3dd |