@tomei/mailer
v0.5.15
Published
Tomei Mailer Package
Downloads
64
Readme
Tomei Mailer
Version Note
Current tomei mailer package version only supports nodemailer and nestjs/mailer
Getting Started
Execute
npm install @tomei/mailer
on your projectEnsure you have setup the environment from
.sampledotenv
in your project.env
file
Package Implementation
- Nodemailer
const nodemailer = require('nodemailer');
const { Mailer } = require('@tomei/mailer');
const mailConfig = {
host: process.env.SMTP_HOST,
port: Number(process.env.SMTP_PORT),
secure: Number(process.env.SMTP_PORT) === 465,
auth: {
user: process.env.EMAIL_SENDER,
pass: process.env.EMAIL_PASSWORD,
},
};
//Tomei Mailer Package Instatiation
const transporter = new Mailer(nodemailer, mailConfig);
async function sendMailFunc() {
await transporter.sendMail({
from: '[email protected]',
to: '[email protected]',
subject: 'Test Email Subject',
text: 'Test Email Content',
});
}
- NestJS/Mailer
import { MailerService } from '@nestjs-modules/mailer'
import { ConfigService } from '@nestjs/config'
import { Mailer, MailerInterfaces } from '@tomei/mailer';
export class MailService {
private mailer: Mailer
constructor(
private mailerService: MailerService,
private configService: ConfigService
) {
const mailConfig: MailerInterfaces.MailConfig = {
host: this.configService.get('SMTP_HOST'),
port: Number(this.configService.get('SMTP_PORT')),
secure: Number(this.configService.get('SMTP_PORT')) === 465,
auth: {
user: this.configService.get('EMAIL_SENDER'),
pass: this.configService.get('EMAIL_PASSWORD'),
},
}
//Tomei Mailer Package Instatiation
this.mailer = new Mailer(mailerService, mailConfig)
}
async sendMailMethod() {
await this.mailer.sendMail({
to: '[email protected]',
subject: 'Test Subject',
template: <email_template_dir_path>,
context: {
System: 'My Project System'
}
})
}
}