Skip to content

Commit fde300e

Browse files
MiffyLiyeWang, Tao
andauthored
feat: send html email api (#102)
扩展`POST /email/@sendEmail`, 新增useHtml可选参数。 Co-authored-by: Wang, Tao <wangtao@36node.com>
1 parent fffa123 commit fde300e

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

openapi.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"hash": "50b02791c7a6d303f38dd96ffece6974ae0eb8160c754e35f57027533f749d24",
2+
"hash": "ce722f966bbb3c4eabd198291cd5cdc8eebf36391ba8eb0458d107822cfc8037",
33
"openapi": "3.0.0",
44
"paths": {
55
"/hello": {
@@ -834,7 +834,7 @@
834834
"description": "No content."
835835
}
836836
},
837-
"summary": "Send plain text email",
837+
"summary": "Send email",
838838
"tags": [
839839
"email"
840840
]
@@ -6356,6 +6356,9 @@
63566356
},
63576357
"content": {
63586358
"type": "string"
6359+
},
6360+
"useHtml": {
6361+
"type": "boolean"
63596362
}
63606363
},
63616364
"required": [

src/email/dto/send-email.dto.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IsEmail, IsNotEmpty, IsString } from 'class-validator';
1+
import { IsBoolean, IsEmail, IsNotEmpty, IsOptional, IsString } from 'class-validator';
22

33
export class SendEmailDto {
44
@IsNotEmpty()
@@ -16,4 +16,8 @@ export class SendEmailDto {
1616
@IsNotEmpty()
1717
@IsString()
1818
content: string;
19+
20+
@IsOptional()
21+
@IsBoolean()
22+
useHtml?: boolean;
1923
}

src/email/email.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class EmailController {
2828
) {}
2929

3030
/**
31-
* Send plain text email
31+
* Send email
3232
*/
3333
@ApiOperation({ operationId: 'sendEmail' })
3434
@ApiNoContentResponse({ description: 'No content.' })

src/email/email.service.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,7 @@ export class EmailService {
3838
sendEmail(dto: SendEmailDto) {
3939
return this.mailer.send({
4040
...dto,
41-
useHtml: false,
42-
});
43-
}
44-
45-
sendHtmlEmail(dto: SendEmailDto) {
46-
return this.mailer.send({
47-
...dto,
48-
useHtml: true,
41+
useHtml: !!dto.useHtml,
4942
});
5043
}
5144
}

0 commit comments

Comments
 (0)