Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

hans-mailer

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hans-mailer

nodemailer wrapper

latest
Source
npmnpm
Version
1.0.4
Version published
Maintainers
1
Created
Source

hans-mailer

nodemailer wrapper

Table of contents

  • Installing
  • Example

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()

FAQs

Package last updated on 01 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts