# midwayjs_mailer
**Repository Path**: onlymry_admin/midwayjs_mailer
## Basic Information
- **Project Name**: midwayjs_mailer
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: Apache-2.0
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 1
- **Created**: 2024-03-02
- **Last Updated**: 2025-09-10
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
### 安装依赖
在 src 目录下新建 components 文件夹, `git clone` 本仓库到该文件夹下,然后在全局目录,执行
```bash
npm i nodemailer --save && npm i @types/nodemailer --save-dev
```
如果在仓库里面有dist包,你可以这样操作 在你的`package.json`里面添加下面👇的依赖
```json
"dependencies":{
"midwayjs_mailer": "https://gitee.com/onlymry_admin/midwayjs_mailer.git"
}
```
然后执行
```bash
yarn install
```
如果咩有,那就老老实实按照第一步来吧!
### 启用组件
在 src/configuration.ts 中引入组件。
```ts
import * as mailer from './components/mailer';
@Configuration({
imports: [
// ...other components
mailer,
],
})
export class MainConfiguration {}
```
### 调用服务
一般情况配合`@midwayjs/captcha`组件使用
```bash
$ npm i @midwayjs/captcha@3 --save
```
记得引入验证码组件,下面是使用案例👇👇👇👇👇
```ts
import { Body, Controller, Inject, Post } from '@midwayjs/core';
import { CaptchaService } from '@midwayjs/captcha';
import { MailerService } from '../../components/mailer';
@Controller('/email')
export class EmailController {
@Inject()
mailerService: MailerService;
@Inject()
captchaService: CaptchaService;
@Post('/send')
@Validate()
async send(@Body() body) {
const { id, text: code } = await this.captchaService.text({
type: 'number',
});
const data = {
to: body.email,
subject: '验证码',
text: '',
html: `${code}