@esouyun/mail
v1.0.0
Published
Mail send module
Maintainers
Readme
@esouyun/mail
简介
@esouyun/mail 是 NestJS 框架的邮件发送模块,基于 Nodemailer 构建,提供简单可靠的邮件发送功能。
特性
- 集成 NestJS 框架,易于配置和使用
- 基于 Nodemailer 构建,支持多种邮件服务提供商
- 提供验证码发送等常用邮件功能
- 支持 HTML 格式邮件内容
- 完整的类型定义支持
安装
pnpm add @esouyun/mail快速开始
- 在 NestJS 模块中导入
MailModule:
import { Module } from '@nestjs/common'
import { ConfigModule } from '@nestjs/config'
import { MailModule } from '@esouyun/mail'
@Module({
imports: [ConfigModule.forRoot(), MailModule]
// ...
})
export class AppModule {}- 在服务中注入
MailService并使用:
import { Injectable } from '@nestjs/common'
import { MailService } from '@esouyun/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
[email protected]API 参考
MailService
sendMail(options: Mail.Options): Promise<void>
发送自定义邮件。
sendVerificationCode(email: string, code: string): Promise<void>
发送验证码邮件。
贡献
欢迎贡献代码、报告问题或提出建议。
许可证
ISC
