@tomei/mailer
TypeScript icon, indicating that this package has built-in type declarations

0.5.11 • Public • Published

Tomei Mailer

Version Note

Current tomei mailer package version only supports nodemailer and nestjs/mailer

Getting Started

  • Execute npm install @tomei/mailer on your project

  • Ensure 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: 'sender@mail.com',
    to: 'recipient@mail.com',
    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: 'recipient@mail.com',
			subject: 'Test Subject',
			template: <email_template_dir_path>,
			context: {
				System: 'My Project System'
			}
		})
	}
}

Readme

Keywords

none

Package Sidebar

Install

npm i @tomei/mailer

Weekly Downloads

42

Version

0.5.11

License

ISC

Unpacked Size

125 kB

Total Files

67

Last publish

Collaborators

  • it-assets