hans-mailer
v1.0.4
Published
nodemailer wrapper
Readme
hans-mailer
nodemailer wrapper
Table of contents
Installing Add the package to your project
npm i hans-mailerusing yarn
yarn add hans-mailerExample
Export Mailer from hans-mailer
const Mailer = require('hans-mailer')
const {HTMLString} = require('hans-mailer')using TypeScript
import Mailer, {HTMLString} from 'hans-mailer'In init mailer file
export function email1({name}: {name: string}): HTMLString {
return `<div>Hello, ${name} this is Email 1</div>`
}
export function email2(): HTMLString {
return '<div>Email 2</div>'
}
export const emailHTMLs = {
email1,
email2,
}
const mailSubjects = {
email1: 'Subject of email 1',
email2: 'Subject of email 2',
}
const mailer = new Mailer({
user: 'sender_email',
password: 'sender_email_passwrod',
service: 'any_service',
appMode: process.env.NODE_ENV // for using test email in development mode
})
mailer.configureTransport({transportHeaders: {'Access-Control-Allow-Origin': '*'}})
// below it is necessary to match keys at mailSubjects and emailHTMLs
mailer.configureMails({
mailSubjects,
emailHTMLs
})
mailer.setTestEmail('[email protected]') // for development
export default mailerWhen use mailer object
mailer.setEmailTo('[email protected]') // in production mode
mailer.setEmailOptions({name: 'John'})
mailer.setTargetEmailName('email1') //
await mailer.send()
mailer.setEmailTo('[email protected]') // in production mode
mailer.setEmailOptions()
mailer.setTargetEmailName('email2') //
await mailer.send()