Skip to content

Commit 335fc95

Browse files
committed
feat: add support for image attachments in mailing service and update template inclusion
1 parent 12f8a49 commit 335fc95

File tree

5 files changed

+35
-9
lines changed

5 files changed

+35
-9
lines changed

server/nest-cli.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
],
1111
"assets": [
1212
{
13-
"include": "mailing/templates/**/*.hbs",
13+
"include": "mailing/templates/**/*.{hbs,png}",
1414
"outDir": "dist/server/src/",
1515
"exclude": "dist/**/*"
1616
},

server/src/mailing/mailing.service.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ describe('MailingService', () => {
5151
subject,
5252
template,
5353
context,
54+
attachments: [
55+
{
56+
filename: 'background-image.png',
57+
cid: 'background-image',
58+
path: `${__dirname}/templates/img/background-image.png`,
59+
},
60+
{
61+
filename: 'logo.png',
62+
cid: 'logo',
63+
path: `${__dirname}/templates/img/logo.png`,
64+
},
65+
],
5466
});
5567
});
5668
});

server/src/mailing/mailing.service.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import { Inject, Injectable, Logger } from '@nestjs/common';
22
import { MailerService } from '@nestjs-modules/mailer';
33

4+
interface EmailOptions {
5+
to: string;
6+
subject: string;
7+
template: string;
8+
context: {
9+
[name: string]: any;
10+
};
11+
}
12+
413
@Injectable()
514
export class MailingService {
615
private readonly logger = new Logger(MailingService.name);
@@ -14,20 +23,25 @@ export class MailingService {
1423
subject,
1524
template,
1625
context,
17-
}: {
18-
to: string;
19-
subject: string;
20-
template: string;
21-
context: {
22-
[name: string]: any;
23-
};
24-
}): Promise<void> {
26+
}: EmailOptions): Promise<void> {
2527
try {
2628
await this.mailerService.sendMail({
2729
to,
2830
subject,
2931
template: `${template}`, // The template file name (without extension)
3032
context, // The context to be passed to the template
33+
attachments: [
34+
{
35+
filename: 'background-image.png',
36+
cid: 'background-image',
37+
path: `${__dirname}/templates/img/background-image.png`,
38+
},
39+
{
40+
filename: 'logo.png',
41+
cid: 'logo',
42+
path: `${__dirname}/templates/img/logo.png`,
43+
},
44+
],
3145
});
3246

3347
this.logger.debug(`Email sent to ${to}`);
15 KB
Loading
8.5 KB
Loading

0 commit comments

Comments
 (0)