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

0.0.3 • Public • Published

📧 revoltMailer

A package to handle email sending with nodemailer.

Todo

  • [] Enable compiler templates like pugjs, handlebars
  • [] Tests

Usage

  • Install the package
  npm install @revolt-digital/mailer
  # or
  yarn add @revolt-digital/mailer
  • Step 1, create one handler file check example in this case: sender.js file, where we can define the transport types we are going to use. import and create transport, Note: Define this transport in server.ts/app.ts (main expressjs file) to use it globally is not a good practice.
import { MailerService, ISendMailOptions } from '@revolt-digital/mailer';

export const sendMail = async (options:ISendMailOptions) => {
  try {
    const sender = new MailerService({
      transport: {
        host: process.env.HOST,
        port: process.env.PORT,
        auth: {
          user: process.env.USERNAME,
          pass: process.env.PASSWORD
        },
      },
      defaults: {
        from: process.env.FROM
      }
    });
    await sender.sendMail(options);
    return;
  } catch (err) {
    throw err;
  }
}
  • Step 2, import sender handler and send email`.
import {sendMail} from './sender';

app.get('/email_smtp', async (req:Request, res: Response)=> {
  await sendMail({
    to: "email@gmail.com",
    subject: "Testing Revolt Mailer module",
    html: "<div>HTML EMAIL</div>",
    text: "text version of email"
  });
  res.send('success')
})

Running the example app

Run yarn install then yarn build in the root folder (the one with this README file).

Then move into the example folder cd example and run yarn install and yarn start.

Then go to http://localhost:8001/email_smtp

/@revolt-digital/mailer/

    Package Sidebar

    Install

    npm i @revolt-digital/mailer

    Weekly Downloads

    21

    Version

    0.0.3

    License

    MIT

    Unpacked Size

    25.6 kB

    Total Files

    39

    Last publish

    Collaborators

    • andresrevolt
    • eapuulesrevolt
    • maitzeth
    • franco-revolt
    • fmrevolt