-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmail.service.ts
More file actions
34 lines (31 loc) · 1.28 KB
/
mail.service.ts
File metadata and controls
34 lines (31 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import config from '@core/config/configuration';
import { UserEntity } from '@core/data/entities';
import { CodexMailOptions, IMailService } from "@core/data/services/mail.service";
import { Injectable } from '@nestjs/common';
import { MailerService } from '@nestjs-modules/mailer';
import { MAIL_DEFAULT_FROM, MAIL_DEFAULT_SUBJECT } from "./models/constants";
@Injectable()
export class MailService implements IMailService<any> {
constructor(private mailerService: MailerService) {}
async send(user: UserEntity, options: CodexMailOptions) {
try {
if(Boolean(config.mail.isEnabled)){
await this.mailerService.sendMail({
to: user.email,
from: options.from || MAIL_DEFAULT_FROM,
subject: options.subject || MAIL_DEFAULT_SUBJECT,
template: options.template,
attachments:options.attachments ?? [],
context: {
name: user.name,
discord: config.social.discord,
email: config.social.email,
...options?.context
},
});
}
} catch (e){
console.warn("Mail could not send: ", e);
}
}
}