# @codeceptjs/mailslurp-helper 中文文档

规范地址：https://npmcn.com/package/%40codeceptjs/mailslurp-helper/

版本：1\.5\.2
npm 元数据更新时间：2026-10-21T10:26:27.493Z
中文译文更新时间：2026-11-10T06:25:06.363Z
软件包许可：ISC

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

原始 npm 页面：https://www.npmjs.com/package/%40codeceptjs/mailslurp-helper
原文对照：https://npmcn.com/package/%40codeceptjs/mailslurp-helper/?lang=original
项目主页：https://github.com/codeceptjs/mailslurp-helper#readme
源码仓库：https://github.com/codeceptjs/mailslurp-helper

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

- 包体积（解压后）：35 kB，7 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：3 个
- peer 依赖：codeceptjs \>=3\.6\.5
- 首次发布：2019-09-16T11:43:16.918Z
- 最新版本发布：2025-10-20T12:24:59.284Z
- 近 30 天下载量：18941（2026-10-10 至 2026-11-08，npm 官方下载统计）
- 已发布版本数：25（近 12 个月 0 个）

## 中文简介

用于测试邮件的 MailSlurp 助手 [https://mailslurp.com (中文(中国大陆) )](https://mailslurp.com/)

## 安装

```sh
npm install @codeceptjs/mailslurp-helper
```

也可以使用：`pnpm add @codeceptjs/mailslurp-helper`、`yarn add @codeceptjs/mailslurp-helper`、`bun add @codeceptjs/mailslurp-helper`

## README

# 用于 CodeceptJS 的 MailSlurp 助手

用于测试电子邮件的 MailSlurp 助手 [MailSlurp 服务](https://mailslurp.com/)。 。 。 . MailSlurp为每次测试创建可支配邮箱,并在测试后将其取出.

## 设置

注册并获取 API 密钥 [邮件流](https://mailslurp.com/)。 。 。 .

```
npm i @codeceptjs/mailslurp-helper --save
```

启用帮助 `codecept.conf.js`。 。 。 .

```js
helpers: {
  MailSlurp: {
    apiKey: '<insert api key here>',
    require: '@codeceptjs/mailslurp-helper'    
  },
}
```

## 使用大小写

在测试中使用此助手来检查电子邮件交互 。 最受欢迎的

-   账户激活
-   恢复被遗忘的密码
-   行动核查

## 使用大小写: 恢复密码

```js
const mailbox = await I.haveNewMailbox();
// wait 10 seconds for an email
const email = await I.waitForLatestEmail(10);
I.seeInEmailSubject('Restore Password');
I.seeInEmailBody('Click link to restore password');
const restoreUrl = email.body.match(/http(s):\/\/(.*?)\s/)[0];
I.amOnPage(restoreUrl);
```

## 在邮箱间切换

```js
const mailbox1 = await I.haveNewMailbox();
const mailbox2 = await I.haveNewMailbox();
I.openMailbox(mailbox1);
const email = I.waitForEmailMatching({ subject: 'Register' });
```

## 在测试中使用自定义请求

```js
const assert = require('assert');
const mailbox = await I.haveNewMailbox();
const email = await I.waitForEmailMatching({ subject: 'Thanks' });
assert.eql(email.subject, 'Thanks for registering')
```

## 自由主义

麻省理工学院

## API 密码

#### 目录

-   [配置](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-configuration)
-   [配置](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-configuration-1)
    -   [属性](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-properties)
-   [有新邮箱](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-havenewmailbox)
-   [已有的邮件箱](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-haveexistingmailbox)
    -   [参数](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-parameters)
-   [打开邮箱](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-openmailbox)
    -   [参数](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-parameters-1)
-   [发送电子邮件](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-sendemail)
    -   [参数](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-parameters-2)
-   [等待 Latest 电子邮件](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-waitforlatestemail)
    -   [参数](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-parameters-3)
-   [等待电子邮件匹配](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-waitforemailmatching)
    -   [参数](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-parameters-4)
-   [等待邮件](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-waitfornthemail)
    -   [参数](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-parameters-5)
-   [抓取电子邮件](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-grabemailsmatching)
    -   [参数](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-parameters-6)
-   [抓取邮件箱中的所有邮件](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-graballemailsfrommailbox)
-   [查看电子邮件对象](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-seeinemailsubject)
    -   [参数](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-parameters-7)
-   [不见电子邮件对象](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-dontseeinemailsubject)
    -   [参数](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-parameters-8)
-   [见电子邮件Body](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-seeinemailbody)
    -   [参数](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-parameters-9)
-   [不见电子邮件Body](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-dontseeinemailbody)
    -   [参数](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-parameters-10)
-   [参见电子邮件地址](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-seeemailisfrom)
    -   [参数](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-parameters-11)
-   [ưμ㼯A](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-seeemailsubjectequals)
    -   [参数](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-parameters-12)
-   [不见电子邮件 Subject 参数](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-dontseeemailsubjectequals)
    -   [参数](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-parameters-13)
-   [参见电子邮件发送次数](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-seenumberofemailattachments)
    -   [参数](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-parameters-14)
-   [参见电子邮件附件](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-seeemailattachment)
    -   [参数](https://npmcn.com/package/%40codeceptjs/mailslurp-helper/#readme-parameters-15)

### 配置

允许在 E2E 测试中通过 [MailSlurp 服务](https://mailslurp.com/)。 。 。 . 在 MailSlurp 注册账户开始 .

需要帮助 `apiKey` 从 MailSlurp 开始

```js
helpers: {
  MailSlurp: {
    apiKey: '<insert api key here>',
    require: '@codeceptjs/mailslurp-helper'
  },
}
```

> 使用.env 文件和环境变量存储敏感数据如 API 密钥

### 配置

-   `apiKey` (需要) - MailSlurp 的 api 密钥
-   `timeout` (默认: 10000) - 等待以毫秒计的电子邮件的时间 .
-   `debug` (默认: 假) - 打印调试日志

类型 : {apiKey: [字符串](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String),超时 : [编号](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)\*,调试: [布尔](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean){\\fn黑体\\fs22\\bord1\\shad0\\3aHBE\\4aH00\\fscx67\\fscy66\\2cHFFFFFF\\3cH808080}你觉得呢

#### 属性

-   `apiKey` **[字符串](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
-   `timeout` **[编号](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)? 吗?**
-   `debug` **[布尔](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)? 吗?**

### 有新邮箱

创建新邮箱。 测试后会删除一个邮箱. 切换到上次创建的邮箱 .

```js
const mailbox = await I.haveNewMailbox();
```

### 已有的邮件箱

使用现有的邮箱.

```js
const mailbox = await I.haveExistingMailbox('94cxxxf4-7231-46ce-9f40-xxxcae39xxxx');
```

#### 参数

-   `mailboxId` **[字符串](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 已存在的 MailSlurp 信箱的标识 .

回返 **[答应](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)< 收件箱 >**

### 打开邮箱

将当前邮箱更改为指定的邮箱 :

```js
const mailbox1 = await I.haveMailbox();
const mailbox2 = await I.haveMailbox();
// mailbox2 is now default mailbox
// switch back to mailbox1
I.openMailbox(mailbox)
```

#### 参数

-   `mailbox`

### 发送电子邮件

从当前邮箱发送邮件, 由 `I.haveNewMailbox()`。 。 。 .

```js
I.sendEmail({
  to: ['user@site.com'],
  subject: 'Hello',
  body: 'World'
});
```

#### 参数

-   `data`

### 等待 Latest 电子邮件

等邮箱里的第一个邮件. 如果邮箱不是空的 - 打开最后一个邮件 .

```js
I.waitForLatestEmail()
// wait for 30 seconds for an email
I.waitForLatestEmail(30);
```

#### 参数

-   `sec` **额?** 等待秒数 .

回返 **[答应](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)< 电子邮件 >** 收到一封电子邮件.

### 等待电子邮件匹配

等待精确的电子邮件匹配查询 。 您可以匹配电子邮件 `from`, (中文(简体) ), `to`, (中文(简体) ), `subject`, (中文(简体) ), `cc`, (中文(简体) ), `bcc` 字段. 我的默认, 非字符串匹配已启用, 因此它搜索是否包含字符串 。 严格匹配( 平等) 预置一个值 `=` 前缀.

```js
 // wait for email with 'password' in subject
const email = await I.waitForEmailMatching({
 subject: 'password',
});

// wait 30 seconds for email with exact subject
const email = await I.waitForEmailMatching({
 subject: '=Forgot password',
}, 30);

//
const email = await I.waitForEmailMatching({
 from: '@mysite.com', // find anything from mysite
 subject: 'Restore password', // with Restore password in subject
});
```

#### 参数

-   `query` **[对象](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 查找电子邮件
-   `sec` **额?** 等待秒数 .

回返 **[答应](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)< 电子邮件 >** 收到一封电子邮件.

### 等待邮件

等邮箱里的邮件数 返回列表中的最后一个邮件 .

```js
// wait for 2 emails
I.waitForNthEmail(2);
// wait for 5 emails for 60 seconds
I.waitForNthEmail(5, 60);
// wait for 2 emails and return the last one
const email = await I.waitForNthEmail(2);
```

#### 参数

-   `number`
-   `sec`

### 抓取电子邮件

返回一组与查询匹配的电子邮件 . 类似 `waitForEmailMatching` 但返回一系列电子邮件.

```js
// return 2 emails from 'user@user.com'
const emails = await I.grabEmailsMatching({ from: 'user@user.com'}, 2);
```

#### 参数

-   `query` **[对象](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 查找电子邮件
-   `num` **额?** 要返回的电子邮件数量 .

回返 **[答应](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\[电子邮件\]** 匹配条件的电子邮件.

### 抓取邮件箱中的所有邮件

从邮箱返回所有邮件 .

```js
const emails = await I.grabAllEmailsFromMailbox();
```

回返 **[答应](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\[电子邮件\]** 电子邮件.

### 查看电子邮件对象

检查当前电子邮件主题包含文本 .

```js
I.seeInEmailSubject('Restore password');
```

需要打开的电子邮件 。 使用其中之一 `waitForEmail*` 打开的方法。 或手动打开 `I.openEmail()` 方法.

#### 参数

-   `text`

### 不见电子邮件对象

检查当前电子邮件主题不包含文本 .

```js
I.seeInEmailSubject('Restore password');
```

需要打开的电子邮件 。 使用其中之一 `waitForEmail*` 打开的方法。 或手动打开 `I.openEmail()` 方法.

#### 参数

-   `text`

### 见电子邮件Body

检查当前邮件正文包含文本 .

```js
I.seeInEmailBody('Click link');
```

需要打开的电子邮件 。 使用其中之一 `waitForEmail*` 打开的方法。 或手动打开 `I.openEmail()` 方法.

#### 参数

-   `text`

### 不见电子邮件Body

检查当前电子邮件正文是否包含文本 .

```js
I.dontSeeInEmailBody('Click link');
```

需要打开的电子邮件 。 使用其中之一 `waitForEmail*` 打开的方法。 或手动打开 `I.openEmail()` 方法.

#### 参数

-   `text`

### 参见电子邮件地址

检查电子邮件来自指定的地址 .

```js
I.seeEmailIsFrom('user@user.com');
```

需要打开的电子邮件 。 使用其中之一 `waitForEmail*` 打开的方法。 或手动打开 `I.openEmail()` 方法.

#### 参数

-   `text`

### ưμ㼯A

检查当前电子邮件主题是否等同于文本 .

```js
I.seeEmailSubjectEquals('Restore password');
```

需要打开的电子邮件 。 使用其中之一 `waitForEmail*` 打开的方法。 或手动打开 `I.openEmail()` 方法.

#### 参数

-   `text`

### 不见电子邮件 Subject 参数

检查当前电子邮件主题不等于文本 .

```js
I.dontSeeEmailSubjectEquals('Restore password');
```

需要打开的电子邮件 。 使用其中之一 `waitForEmail*` 打开的方法。 或手动打开 `I.openEmail()` 方法.

#### 参数

-   `text`

### 参见电子邮件发送次数

检查当前邮件是否期望附件数量 .

```js
I.seeNumberOfEmailAttachments(2);
```

需要打开的电子邮件 。 使用其中之一 `waitForEmail*` 打开的方法。 或手动打开 `I.openEmail()` 方法.

#### 参数

-   `number`

### 参见电子邮件附件

检查当前邮件是否有带有指定名称的附件 .

```js
I.seeEmailAttachment('ExampleAttachment.pdf');
```

注意Mailslurp SDK删除以附件为名的特殊字符, 例如"example-Attachment.pdf"将取名"example-Attachment.pdf".

需要打开的电子邮件 。 使用其中之一 `waitForEmail*` 打开的方法。 或手动打开 `I.openEmail()` 方法.

#### 参数

-   `nameRegExp`

## 常见问题

### @codeceptjs/mailslurp-helper 是什么？

用于测试邮件的 MailSlurp 助手 https://mailslurp\.com \(中文\(中国大陆\) \)

### 如何安装 @codeceptjs/mailslurp-helper？

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

### @codeceptjs/mailslurp-helper 支持 TypeScript 吗？

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

### @codeceptjs/mailslurp-helper 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @codeceptjs/mailslurp-helper 可以商用吗？

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

### @codeceptjs/mailslurp-helper 的下载量有多少？

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

### @codeceptjs/mailslurp-helper 还在维护吗？

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

