# @haftahave/serverless-ses-template 中文文档

规范地址：https://npmcn.com/package/%40haftahave/serverless-ses-template/

版本：6\.2\.0
npm 元数据更新时间：2025-04-29T21:00:04.318Z
中文译文更新时间：2026-11-17T06:01:26.022Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40haftahave/serverless-ses-template
原文对照：https://npmcn.com/package/%40haftahave/serverless-ses-template/?lang=original
项目主页：https://github.com/Enase/serverless-ses-template
源码仓库：https://github.com/Enase/serverless-ses-template

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：54.1 kB，21 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- Node.js 要求：\>=20\.18\.1
- 运行依赖：2 个
- peer 依赖：serverless \>=3\.2\.0 \|\| \>=4\.0\.0
- 首次发布：2018-09-11T20:43:09.242Z
- 最新版本发布：2025-04-29T21:00:04.105Z
- 近 30 天下载量：10742（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：40（近 12 个月 0 个）

## 中文简介

Amazon 简单电子邮件服务的无服务器模板同步插件

## 安装

```sh
npm install @haftahave/serverless-ses-template
```

也可以使用：`pnpm add @haftahave/serverless-ses-template`、`yarn add @haftahave/serverless-ses-template`、`bun add @haftahave/serverless-ses-template`

## README

[![NPM](https://img.shields.io/npm/v/@haftahave/serverless-ses-template.svg)](https://www.npmjs.com/package/@haftahave/serverless-ses-template) [![npm](https://img.shields.io/npm/dt/@haftahave/serverless-ses-template.svg)](https://www.npmjs.com/package/@haftahave/serverless-ses-template) [![Build Status](https://app.travis-ci.com/Enase/serverless-ses-template.svg?branch=master)](https://app.travis-ci.com/Enase/serverless-ses-template) [![slack](https://img.shields.io/badge/Join%20Our%20Community-Slack-blue)](https://enasetech.slack.com/archives/C05S2SZNRTM) [![Made in Ukraine](https://img.shields.io/badge/made_in-Ukraine-ffd700.svg?labelColor=0057b7)](https://stand-with-ukraine.pp.ua/)

[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner2-direct.svg)](https://vshymanskyy.github.io/StandWithUkraine/)

# 亚马逊简易电子邮件服务模板同步插件

允许自动创建、更新和删除的无服务器插件 AWS SES 模板使用配置文件并保存您的 AWS SES 模板 与您的配置文件同步 .

**需求** 节点20+

* * *

**: zap: 特性**

-   允许宣布在部署前阶段同步的电子邮件模板
-   允许您在同步时在模板名称中选择添加舞台
-   允许您按指定名称列出和删除 SES 模板

* * *

#### 实例

-   [无服务器的简单插件集成 v4](https://npmcn.com/package/%40haftahave/serverless-ses-template/examples/simple-service-v4)
-   [简单的插件集成, 无服务器 v3](https://npmcn.com/package/%40haftahave/serverless-ses-template/examples/simple-service)
-   [与资产管理的插件整合](https://npmcn.com/package/%40haftahave/serverless-ses-template/examples/cloud-front-service) (未维持)

* * *

> 🚨 **重要通知**数字 :
> 
> 从 [6.x (单位:千美元)](https://github.com/Enase/serverless-ses-template) 版本,插件已切换到 **[纯无害环境管理](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c)** 并需要无服务器 [页:1](https://github.com/serverless/serverless/releases/tag/v3.2.0) 或更新.
> 
> 如果你需要的话 **CJS 软件包** 使用情况 [5.x 电话](https://github.com/Enase/serverless-ses-template/tree/5.1.0) 插件序列
> 
> 如果您需要兼容性 `serverless<3.0.0`标记 [页:1](https://github.com/Enase/serverless-ses-template/tree/4.0.7)。 。 。 .

* * *

#### 安装

`npm install @haftahave/serverless-ses-template`

#### 配置

-   全体 **@haftahave/ serverless-ses-template (英语)** 配置参数为可选

```yaml
# add to your serverless.yml

plugins:
  - '@haftahave/serverless-ses-template'

custom:
  sesTemplates:
    addStage: true                             # Specifies whether to add stage to template name (default false)
    configFile: './custom-config-file/path.js' # Config file path (default './ses-email-templates/index.js')
    deployHook: 'after:deploy:deploy'          # Specifies serverless lifecycle event plugin use to deploy templates (default 'before:deploy:deploy')
    disableAutoDeploy: true                    # Specifies whether to sync templates while sls deploy and remove (default false)
    region: 'us-west-2'                        # Specifies AWS region for SES templates (not required)
    removeMissed: false                        # Set this flag in order to remove templates those are not present in your configuration file. (not required, default false)
```

* * *

### 模板配置文件

模板配置文件应该是返回对象数组(需要所有密钥)的async函数:

```javascript
/**
 * @param {Object} serverless - Serverless instance
 * @param {Object} options - runtime options
 * @returns {Promise<{name: string, subject: string, html: string, text: string}[]>}
 */
const templateConfiguration = async (serverless, options) => [{
    name: 'example_name',
    subject: 'Your subject',
    html: '<h1>Hello world!</h1>',
    text: 'Hello world!',
}];

export default templateConfiguration
```

真实世界的例子 [这里](https://npmcn.com/package/%40haftahave/serverless-ses-template/examples/simple-service-v4/ses-email-templates/index.js)。 。 。 .

## 插件按以下顺序解决区域 :

-   名为 CLI 的参数 `sesTemplatesRegion` - 最高优先级
-   `serverless.yml` 已命名的插件配置参数 `region`
-   名为 CLI 的参数 `region`
-   回落到默认区域解析( 在无服务器. yml 中定义的第一阶段的第一个区域)

## 插件按以下顺序解决模板配置文件路径 :

-   名为 CLI 的参数 `sesTemplateConfig` - 最高优先级
-   `serverless.yml` 已命名的插件配置参数 `configFile`
-   倒向默认 `./ses-email-templates/index.js`

## 使用和命令行选项

### 部署

运行 `sls ses-template deploy` 以同步您的电子邮件模板.

可选 CLI 选项 :

```
--sesTemplatesRegion The region used to populate your templates. Default: see "Region fallback sequence" in readme.md. [OPTIONAL]
--sesTemplateConfig  Template configuration file path. Default: see "Template configuration file sequence" in readme.md. [OPTIONAL]
--stage        The stage used to populate your templates. Default: the first stage found in your project. [OPTIONAL]
--removeMissed Set this flag in order to remove templates those are not present in your configuration file. [OPTIONAL]
```

* * *

### 列表模板

运行 `sls ses-template list` 以列出您的电子邮件模板.

CLI 选项 :

```
--sesTemplatesRegion The region used to list your templates. Default: see "Region fallback sequence" in readme.md. [OPTIONAL]
--filter <string>    Display templates that contain <string>. [OPTIONAL]
```

### 删除模板

运行 `sls ses-template delete --template template_name_goes_here` 删除您的电子邮件模板.

CLI 选项 :

```
--template    The template name you are going to delete [REQUIRED]
--sesTemplatesRegion The region used to populate your templates. Default: see "Region fallback sequence" in readme.md. [OPTIONAL]
--stage       The stage used to populate your templates. Default: the first stage found in your project. [OPTIONAL]
```

## 链接

-   [使用 Amazon SES API 发送个性化电子邮件](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/send-personalized-email-api.html)
-   [Amazon SES API 发送 Templated 电子邮件](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SES.html#sendTemplatedEmail-property)

## 许可证

麻省理工学院

## 常见问题

### @haftahave/serverless-ses-template 是什么？

Amazon 简单电子邮件服务的无服务器模板同步插件

### 如何安装 @haftahave/serverless-ses-template？

在项目目录运行 npm install @haftahave/serverless-ses-template，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：serverless（\>=3\.2\.0 \|\| \>=4\.0\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @haftahave/serverless-ses-template 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @haftahave/serverless-ses-template 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @haftahave/serverless-ses-template 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=20\.18\.1。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @haftahave/serverless-ses-template 可以商用吗？

@haftahave/serverless-ses-template 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @haftahave/serverless-ses-template 的下载量有多少？

根据 npm 官方下载统计，@haftahave/serverless-ses-template 在 2026/10/17 – 2026/11/15 这 30 天内被下载 10,742 次，日均约 358 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @haftahave/serverless-ses-template 还在维护吗？

最新版本 6\.2\.0 发布于 2025/04/30（1\.5 年前）；至今共发布 40 个版本，其中过去 12 个月发布了 0 个；首次发布于 2018/09/12。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

