npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

yash-mailer

v0.1.7

Published

PureRhyme's Mailer Service

Downloads

16

Readme

PureRhyme Mailer 📧

璞瑞雅诗邮件服务模块 - 基于 MidwayJS 和 Nodemailer 的企业级邮件发送服务

npm version TypeScript MidwayJS License

📖 项目简介

PureRhyme Mailer 是一个基于 MidwayJS 框架的邮件服务模块,提供稳定、可配置的邮件发送功能。支持模板化邮件内容,便于集成和维护。

✨ 核心特性

  • 🚀 高性能: 基于 MidwayJS 框架,支持依赖注入和模块化架构
  • 📧 邮件发送: 使用 Nodemailer 实现可靠的邮件发送服务
  • 🎨 模板支持: 内置 HTML 邮件模板,支持验证码邮件等场景
  • ⚙️ 配置化: 通过配置文件管理 SMTP 等参数`
  • 🔒 类型安全: 完全使用 TypeScript 编写,提供完整的类型定义
  • 🧪 测试覆盖: 提供 Jest 单元测试支持

📦 安装

# 使用 npm
npm install yash-mailer

# 使用 yarn
yarn add yash-mailer

# 使用 pnpm
pnpm add yash-mailer

🚀 快速开始

1. 配置邮件服务

在你的 MidwayJS 项目中添加邮件配置:

// src/config/config.default.ts
export default {
  mailer: {
    host: 'smtp.example.com',
    port: 587,
    secure: false, // true for 465, false for other ports
    auth: {
      user: '[email protected]',
      pass: 'your-password'
    }
  }
};

2. 注册服务

// src/configuration.ts
import { Configuration } from '@midwayjs/core';
import * as mailer from 'yash-mailer';

@Configuration({
  imports: [
    mailer
  ]
})
export class MainConfiguration {}

3. 使用邮件服务

import { Inject, Controller, Post, Body } from '@midwayjs/core';
import { MailService } from 'yash-mailer';

@Controller('/api/mail')
export class MailController {
  @Inject()
  mailService: MailService;

  @Post('/send-verification')
  async sendVerification(@Body() body: { email: string; code: string }) {
    await this.mailService.send({
      to: body.email,
      subject: '验证码邮件',
      html: JSON.stringify({
        code: body.code,
        event: 0 // EmailEvent.Verification
      })
    });
    
    return { success: true };
  }
}

📚 API 文档

MailService

邮件服务的主要类,提供邮件发送功能。

方法

send(options: SendMailOptions): Promise<void>

发送邮件的主要方法。

参数:

  • options: Nodemailer 的 SendMailOptions 对象
    • to: 收件人邮箱地址
    • subject: 邮件主题
    • html: 邮件内容(JSON 字符串格式)

示例:

await mailService.send({
  to: '[email protected]',
  subject: '验证码邮件',
  html: JSON.stringify({
    code: '123456',
    event: EmailEvent.Verification
  })
});
sendVerificationMail(code: string, options: SendMailOptions): Promise<string>

发送验证码邮件的便捷方法。

参数:

  • code: 验证码
  • options: 邮件选项

返回:

  • Promise<string>: 邮件消息 ID

接口定义

MailerConfigurationType

interface MailerConfigurationType {
  host: string;      // SMTP 服务器地址
  port: number;      // SMTP 端口
  secure: boolean;   // 是否使用 SSL/TLS
  auth: {
    user: string;    // 邮箱用户名
    pass: string;    // 邮箱密码
  };
}

EmailEvent

enum EmailEvent {
  Verification = 0  // 验证码邮件
}

🎨 邮件模板

验证码邮件模板

内置的验证码邮件模板具有以下特性:

  • 🎨 现代化的设计风格
  • 📱 响应式布局,支持移动设备
  • 🔒 安全提示信息
  • 🏢 品牌定制化内容

模板预览:

  • 包含 PureRhyme 品牌 Logo
  • 突出显示验证码(36px 大字体)
  • 10分钟有效期提示
  • 安全警告信息
  • 隐私政策链接

🔧 开发指南

环境要求

  • Node.js >= 16.x
  • TypeScript ~4.8.0
  • MidwayJS ^3.20.4

开发环境搭建

# 克隆项目
git clone <repository-url>
cd mailer

# 安装依赖
pnpm install

# 构建项目
pnpm build

# 运行测试
pnpm test

# 测试覆盖率
pnpm cov

# 代码检查
pnpm lint

# 修复代码格式
pnpm lint:fix

项目结构

src/
├── config/
│   └── config.default.ts     # 默认配置
├── html/
│   └── verification.ts        # 验证码邮件模板
├── service/
│   └── mailer.service.ts      # 邮件服务实现
├── configuration.ts           # MidwayJS 配置
├── index.ts                   # 模块入口
└── interface.ts              # 类型定义

test/
└── index.test.ts             # 单元测试

添加新的邮件模板

  1. src/html/ 目录下创建新的模板文件
  2. interface.ts 中添加新的邮件事件类型
  3. MailService 中添加对应的发送方法
  4. 更新单元测试

🧪 测试

项目使用 Jest 进行单元测试:

# 运行所有测试
pnpm test

# 查看测试覆盖率
pnpm cov

# 监视模式运行测试
npm run test:watch

📋 版本发布

# 构建并发布
pnpm release

🤝 贡献指南

  1. Fork 项目
  2. 创建特性分支 (git checkout -b feature/AmazingFeature)
  3. 提交更改 (git commit -m 'Add some AmazingFeature')
  4. 推送到分支 (git push origin feature/AmazingFeature)
  5. 打开 Pull Request

代码规范

项目使用 mwts 进行代码检查和格式化:

# 检查代码规范
pnpm lint

# 自动修复代码格式
pnpm lint:fix

📄 许可证

本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。

🔗 相关链接

📞 技术支持

如果您在使用过程中遇到问题,请通过以下方式联系我们:

  • 提交 Issue
  • 发送邮件至技术支持团队