Skip to content

Commit c1edc34

Browse files
committed
🐛 fix send mail after build typescript
1 parent 74059f8 commit c1edc34

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

src/utils/email.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,29 @@ export default class Email {
3535
}
3636

3737
private async send(template: string, subject: string) {
38-
// Generate HTML template based on the template string
39-
const html = pug.renderFile(`${__dirname}/../views/${template}.pug`, {
40-
firstName: this.#firstName,
41-
subject,
42-
url: this.url,
43-
});
44-
// Create mailOptions
45-
const mailOptions = {
46-
from: this.#from,
47-
to: this.#to,
48-
subject,
49-
text: convert(html),
50-
html,
51-
};
38+
try {
39+
// Generate HTML template based on the template string
40+
const html = pug.renderFile(`${__dirname}/../views/${template}.pug`, {
41+
firstName: this.#firstName,
42+
subject,
43+
url: this.url,
44+
});
45+
46+
// Create mailOptions
47+
const mailOptions = {
48+
from: this.#from,
49+
to: this.#to,
50+
subject,
51+
text: convert(html),
52+
html,
53+
};
5254

53-
// Send email
54-
const info = await this.newTransport().sendMail(mailOptions);
55-
console.log(nodemailer.getTestMessageUrl(info));
55+
// Send email
56+
const info = await this.newTransport().sendMail(mailOptions);
57+
console.log(nodemailer.getTestMessageUrl(info));
58+
} catch (error) {
59+
console.error('Error during send mail :', error);
60+
}
5661
}
5762

5863
async sendVerificationCode() {

0 commit comments

Comments
 (0)