Skip to content

Commit 6dfb884

Browse files
committed
refactor: create mail service
1 parent fe24559 commit 6dfb884

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

src/services/mail.service.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import nodemailer from 'nodemailer';
2+
3+
export class MailService {
4+
private transporter = nodemailer.createTransport({
5+
host: process.env.SMTP_HOST,
6+
port: parseInt(process.env.SMTP_PORT as string, 10),
7+
secure: process.env.SMTP_SECURE === 'true',
8+
auth: {
9+
user: process.env.SMTP_USER,
10+
pass: process.env.SMTP_PASS
11+
}
12+
});
13+
14+
async sendVerificationEmail(email: string, token: string) {
15+
const url = `${process.env.FRONTEND_URL}/confirm-email?token=${token}`;
16+
await this.transporter.sendMail({
17+
from: process.env.FROM_EMAIL,
18+
to: email,
19+
subject: 'Verify your email',
20+
text: `Click to verify your email: ${url}`
21+
});
22+
}
23+
24+
async sendPasswordResetEmail(email: string, token: string) {
25+
const url = `${process.env.FRONTEND_URL}/reset-password?token=${token}`;
26+
await this.transporter.sendMail({
27+
from: process.env.FROM_EMAIL,
28+
to: email,
29+
subject: 'Reset your password',
30+
text: `Reset your password: ${url}`
31+
});
32+
}
33+
}

0 commit comments

Comments
 (0)