-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmail.service.ts
59 lines (52 loc) · 1.86 KB
/
mail.service.ts
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { Injectable } from '@nestjs/common';
import { MailerService } from '@nestjs-modules/mailer';
import { InjectRepository } from '@nestjs/typeorm';
import { User } from 'src/user/user.model';
import { Repository } from 'typeorm';
import { AppConfigService } from 'src/config/config.service';
@Injectable()
export class MailService {
constructor(
@InjectRepository(User)
private userRepository: Repository<User>,
private readonly mailerService: MailerService,
private configService: AppConfigService,
) {}
async sendConfirmationEmail(email: string, token: string) {
const confirmUrl = `https://${this.configService.mailDomain}/auth/confirm?token=${token}`;
await this.mailerService.sendMail({
to: email,
subject: 'Confirm Your Email',
template: './confirmation',
context: { confirmUrl }, // Data for template
});
}
async sendPasswordResetEmail(user: User, token: string) {
const frontendUrl = this.configService.frontendUrl;
const url = `${frontendUrl}/reset-password?token=${token}`;
await this.mailerService.sendMail({
to: user.email,
subject: 'Password Reset Request',
template: './passwordReset',
context: {
name: user.username,
firstName: user.username,
url,
},
});
}
// async sendConfirmationEmail(user: User, token: string) {
// const frontendUrl = this.configService.get('FRONTEND_URL');
// const url = `${frontendUrl}/confirm-email?token=${token}`;
// await this.mailerService.sendMail({
// to: user.email,
// subject: 'Welcome! Confirm Your Email',
// template: './confirmation', // This will use the confirmation.hbs template
// context: { // Data to be sent to the template
// name: user.username,
// firstName: user.firstName || user.username,
// url,
// },
// });
// }
}