使用触发器电子邮件扩展程序管理传送状态
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
当某个文档被添加到集合之后,扩展程序会选取该文档进行电子邮件传送处理。在处理电子邮件时,此扩展程序会在文档中创建并更新一个 delivery
字段。
电子邮件传送处理
可以使用以下字段填充 delivery
字段:
- state:
PENDING
、PROCESSING
、SUCCESS
或 ERROR
之一。
- startTime:电子邮件处理开始时间的时间戳。
- endTime:电子邮件处理完成(即以
SUCCESS
或 ERROR
状态结束)时间的时间戳。
- error:如果发生电子邮件传送错误,此处会填充错误消息。
- attempts:尝试传送此电子邮件的次数。
- leaseExpireTime:如果挂起或超时,则处于
PROCESSING
状态的时间应被视为错误。
- info:成功传送电子邮件(至少发送至一个地址)后,系统将使用以下字段填充此字段:
- messageId:已传送的电子邮件的邮件 ID。
- accepted:已将电子邮件成功传送到的电子邮件地址数组。
- rejected:电子邮件无法传送到的电子邮件地址数组。
- pending:SMTP 暂时拒绝的电子邮件地址数组。
- response:来自 SMTP 服务器的最后响应。
电子邮件通常从 PENDING
发送至 PROCESSING
,然后再发送至 SUCCESS
或 ERROR
。一旦进入 SUCCESS
或 ERROR
状态,对文档进行的其他更改将不会触发扩展程序发送另一封电子邮件。要重新发送包含文档更新的电子邮件,您可以将 state
更改为 PENDING
或 RETRY
。
手动重试
在某些情况下,电子邮件在传送失败之后可以恢复,或者只需对文档进行少量的手动修改即可更正并正确传送。虽然重试不是自动进行的,但您可以手动将 delivery
字段中的 state
更改为 RETRY
,以便扩展程序再次尝试传送电子邮件(并增加 attempts
的数量)。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-12。
[null,null,["最后更新时间 (UTC):2025-08-12。"],[],[],null,["\u003cbr /\u003e\n\nWhen a document is added to the collection, the extension picks it up for email\ndelivery processing. The extension creates and updates a `delivery` field in the\ndocument as it processes the email.\n\nEmail delivery processing\n\nThe `delivery` field can be populated with the following fields:\n\n- **state:** One of `PENDING`, `PROCESSING`, `SUCCESS`, or `ERROR`.\n- **startTime:** Timestamp when email processing began.\n- **endTime:** Timestamp when email processing completed (that is, ended in either a `SUCCESS` or `ERROR` state).\n- **error:** If there was an email delivery error, an error message will be populated here.\n- **attempts:** Number of delivery attempts for this email.\n- **leaseExpireTime:** In case of a hang or timeout, the time at which a `PROCESSING` state should be considered an error.\n- **info:** After successful email delivery (to at least one address), this field will be populated with the following fields:\n - **messageId:** The message ID of the delivered email.\n - **accepted:** Array of email addresses to which the email was successfully delivered.\n - **rejected:** Array of email addresses to which the email could not be delivered.\n - **pending:** Array of email addresses that were temporarily rejected by SMTP.\n - **response:** The last response from the SMTP server.\n\nAn email will typically go from `PENDING` to `PROCESSING` to either `SUCCESS` or\n`ERROR`. Once in the `SUCCESS` or `ERROR` state, additional changes to the\ndocument will not trigger the extension to send another email. To resend an\nemail with document updates, you can change the `state` to `PENDING` or `RETRY`.\n\nManual retries\n\nThere are instances in which email delivery fails in a recoverable fashion or\nthe document can be manually corrected for proper delivery with minor\nmodifications. While retries are not automatic, you can manually change the\n`state` in the `delivery` field to `RETRY` so that the extension attempts email\ndelivery again (and increments the number of `attempts`)."]]