1.0.4 • Published 3 years ago

hans-mailer v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

hans-mailer

nodemailer wrapper

Table of contents

Installing Add the package to your project

npm i hans-mailer

using yarn

yarn add hans-mailer

Example

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('test.email@test.com') // for development

export default mailer

When use mailer object

mailer.setEmailTo('john.mailer@inbox.lv') // in production mode
mailer.setEmailOptions({name: 'John'})
mailer.setTargetEmailName('email1') // 
await mailer.send()

mailer.setEmailTo('helena.mailer@inbox.lv') // in production mode
mailer.setEmailOptions()
mailer.setTargetEmailName('email2') // 
await mailer.send()
1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago