@cemalgnlts/mailjs

中文文档
3.1.2发布于 2026/03/06MITTypeScriptESM + CJS近 30 天下载 13.9万

A JavaScript wrapper around the mail.tm api.

原始使用文档
文档目录22 节
  1. Constructor
  2. Domain
  3. List Domains
  4. Get Domain
  5. Account
  6. Create Account
  7. Login
  8. Login With Token
  9. Get Account Data
  10. Delete Account
  11. Message
  12. List messages
  13. Read a message
  14. Delete a message
  15. Make a message readed or unreaded.
  16. Events
  17. on
  18. off
  19. Source
  20. Get source
  21. Helper Methods
  22. Create random account.

Mailjs

A JavaScript wrapper around the mail.tm api.

Probably one of the best API for creating temporary email accounts.

  • Usage of our API for illegal activity is strictly prohibited.
  • It is forbidden to sell programs or earn from it that exclusively uses our API (for example, creating a competing temp mail client and charging for it's usage).
  • The general quota limit is 8 queries per second (QPS) per IP address.

If your goal is to test your emails, check out smpt.dev for more tools.

Installation

npm

npm install @cemalgnlts/mailjs

yarn

yarn add @cemalgnlts/mailjs

CDN

<!-- It is only needed to listen to new messages. -->
<script src="https://cdn.jsdelivr.net/gh/cemalgnlts/[email protected]/eventsource.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@cemalgnlts/[email protected]/dist/mailjs.min.js"></script>

Quickstart

  • Nodejs (CommonJS)
const Mailjs = require("@cemalgnlts/mailjs");
  • Nodejs (ESM)
import Mailjs from "@cemalgnlts/mailjs";
  • Browser
<!-- You can exlude this if not listening to events. -->
<script src="https://cdn.jsdelivr.net/gh/cemalgnlts/[email protected]/eventsource.min.js"></script>
<!-- Mailjs library -->
<script src="https://cdn.jsdelivr.net/npm/@cemalgnlts/[email protected]/dist/mailjs.min.js"></script>

EventSourcePolyfill is only for listening to new incoming messages, see Events title for more information. Add EventSourcePolyfill before Mailjs.

const mailjs = new Mailjs();

mailjs.createOneAccount()
    .then(account => console.log(account.data));

For more reference visit /examples directory.

Documentation

Returns a Promise object after the function is called. If the request is sent correctly, status returns true.

If it returns incorrect, the status will be false and the message in the data is also added.

If there is no error, status always returns true.

With statusCode you can access the status code returned as a result of the request. statusCode is only for debugging, just look at status to see if an error has occurred.

A successfull response example:

{
  "status": true,
  "statusCode": 200,
  "message": "ok",
  "data": {}
}

A failed response example:

{
  "status": false,
  "statusCode": 410,
  "message": "Invalid credentials.",
  "data": {}
}

Example use:

const acc = await mailjs.createOneAccount();

// If there is a error.
if(!acc.status) {
  // Show the cause of the error.
  console.error(acc.message);

  return;
}

// If successful, access the data.
console.log(acc.data);

To see all results, check out the API page: https://api.mail.tm/.

User needs to login to access JWT token. Registration does not return this information, log in after registration.

After the login process, the user's JWT token and ID are assigned to mailjs.token and mailjs.id.


Constructor

The general quota limit is 8 queries per second (QPS) per IP address. But this may change over time. If a timeout error occurs, the library waits 1 second and repeats the request. If after 3 attempts the problem is not solved, it throws an error.

To turn this off or increase the number of attempts, specify this with rateLimitRetries when creating the constructor object. Default value is 3.

Disable it:

const mailjs = new Mailjs({ rateLimitRetries: 0 });

Or if a timeout error occurs, try 5 times waiting 1 second each:

const mailjs = new Mailjs({ rateLimitRetries: 5 });

Domain

List Domains

mailjs.getDomains()
  .then(console.log);

Get Domain

mailjs.getDomain("[domain id]")
  .then(console.log);

Account

Create Account

mailjs.register("[email protected]", "password")
  .then(console.log);

Login

mailjs.token and mailjs.id can be used to access the user token and id later.

mailjs.login("[email protected]", "password")
  .then(console.log);

Login With Token

If you use the JWT token stored in mailjs.token after login, it will allow you to login without username and password.

mailjs.loginWithToken("eyJ0eXAiO...")
  .then(console.log);

Get Account Data

mailjs.me()
  .then(console.log);

Delete Account

mailjs.deleteMe()
  .then(console.log);

You can also use the id to access the user's information and delete their account.

mailjs.deleteAccount("[account id]")
  .then(console.log);
mailjs.getAccount("[account id]")
  .then(console.log);

Message

List messages

Gets all the Message resources of a given page.

mailjs.getMessages()
  .then(console.log);

Read a message

Retrieves a Message resource with a specific id (It has way more information than a message retrieved with GET /messages but it hasn't the "intro" member)

mailjs.getMessage("[message id]")
  .then(console.log);

Delete a message

mailjs.deleteMessage("[message id]")
  .then(console.log);

Make a message readed or unreaded.

true for make readed. false for make unreaded.

mailjs.setMessageSeen("[message id]", true)
  .then(console.log);

Events

Events are the Server Sent Events which are fired when message arrive, seen or delete. It also fires the error, open state.

on

Open an event listener to messages and error.

// Add it before other activities if you need it.
mailjs.on("open", msg => console.log("Event listening has begun."));

// When a new message arrives.
mailjs.on("arrive", msg => console.log(`Message id: ${msg.id} has arrived (${msg.intro}).`));

// When a message is marked as read.
mailjs.on("seen", msg => console.log(`Message id: ${msg.id} marked as seen.`));

// When a message is deleted.
mailjs.on("delete", msg => console.log(`Message id: ${msg.id} has been deleted.`));

// If an error occurs during listening.
mailjs.on("error", err => console.error("Something went wrong:", err));

off

Clears the events and safely closes event listener.

mailjs.off();

Source

Get source

Gets a Message's Source resource (If you don't know what this is, you either don't really want to use it or you should read this!)

mailjs.getSource("[message id]")
  .then(console.log)

Helper Methods

Create random account.

mailjs.createOneAccount(useUUID: boolean = false)

Creates and logs in an account with a random username and password. The same email address can be used during automatic email creation. To prevent this, you can use a UUID as the email address: mailjs.createOneAccount(true)

mailjs.createOneAccount()
  .then(console.log);

Response

{
  "status": true,
  "message": "ok",
  "data": {
    "username": "[email protected]",
    "password": "my-password"
  }
}

Questions And Suggestions

If you have any questions or suggestions, please contact us via email [email protected] or discord.

版本与发布记录

@cemalgnlts/mailjs 共发布 11 个版本,首次发布于 2021/09/05;过去 12 个月发布了 1 个版本。

版本发布日期距今
3.1.2latest2026/03/068 个月前
3.1.12025/07/031.3 年前
3.1.02025/05/221.5 年前
3.0.12023/11/122 年前
3.0.02023/10/213 年前
2.2.02023/04/243 年前

关于 @cemalgnlts/mailjs 的常见问题

@cemalgnlts/mailjs 是什么?

A JavaScript wrapper around the mail.tm api.

如何安装 @cemalgnlts/mailjs?

在项目目录运行 npm install @cemalgnlts/mailjs,或使用 pnpm add / yarn add / bun add。

@cemalgnlts/mailjs 支持 TypeScript 吗?

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

@cemalgnlts/mailjs 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@cemalgnlts/mailjs 可以商用吗?

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

@cemalgnlts/mailjs 的下载量有多少?

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

@cemalgnlts/mailjs 还在维护吗?

最新版本 3.1.2 发布于 2026/03/06(8 个月前);至今共发布 11 个版本,其中过去 12 个月发布了 1 个;首次发布于 2021/09/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。