Skip to content

Instantly share code, notes, and snippets.

@antonkalik
Created March 27, 2024 20:53
Show Gist options
  • Save antonkalik/c374e69d670db367cccdf3958ead73d6 to your computer and use it in GitHub Desktop.
Save antonkalik/c374e69d670db367cccdf3958ead73d6 to your computer and use it in GitHub Desktop.
Email Service with initialization
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