@testboard/mail
简介
@testboard/mail
是 TestBoard 平台的邮件发送模块,基于 NestJS 和 Nodemailer 构建,提供简单可靠的邮件发送功能。
特性
- 集成 NestJS 框架,易于配置和使用
- 基于 Nodemailer 构建,支持多种邮件服务提供商
- 提供验证码发送等常用邮件功能
- 支持 HTML 格式邮件内容
- 完整的类型定义支持
安装
pnpm add @testboard/mail
快速开始
- 在 NestJS 模块中导入
MailModule
:
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { MailModule } from '@testboard/mail';
@Module({
imports: [ConfigModule.forRoot(), MailModule]
// ...
})
export class AppModule {}
- 在服务中注入
MailService
并使用:
import { Injectable } from '@nestjs/common';
import { MailService } from '@testboard/mail';
@Injectable()
export class UserService {
constructor(private readonly mailService: MailService) {}
async sendVerification(email: string, code: string) {
await this.mailService.sendVerificationCode(email, code);
}
}
文档
详细文档请参阅 docs
目录:
配置
在 .env
文件中配置邮件服务:
MAIL_HOST=smtp.example.com
MAIL_PORT=587
MAIL_SECURE=false
MAIL_USER=your-username
MAIL_PASS=your-password
MAIL_FROM=TestBoard <noreply@example.com>
API 参考
MailService
sendMail(options: Mail.Options): Promise<void>
发送自定义邮件。
sendVerificationCode(email: string, code: string): Promise<void>
发送验证码邮件。
贡献
欢迎贡献代码、报告问题或提出建议。
许可证
ISC