Created
March 27, 2024 20:53
-
-
Save antonkalik/c374e69d670db367cccdf3958ead73d6 to your computer and use it in GitHub Desktop.
Email Service with initialization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import process from 'process'; | |
import * as nodemailer from 'nodemailer'; | |
import * as dotenv from 'dotenv'; | |
dotenv.config(); | |
export class EmailService { | |
private static transporter: nodemailer.Transporter; | |
private static env = { | |
USER: process.env.MAIL_USER, | |
PASS: process.env.MAIL_PASSWORD, | |
}; | |
public static initialize() { | |
try { | |
EmailService.transporter = nodemailer.createTransport({ | |
service: 'gmail', | |
auth: { | |
user: this.env.USER, | |
pass: this.env.PASS, | |
}, | |
}); | |
} catch (error) { | |
console.error('Error initializing email service'); | |
throw error; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment