@dupkey/mail
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

@dupkey/mail

Email messages and mailer. Provides response and transport interfaces so new transport agents can be added.

Currently only supports Mailgun transactional email templates.

Install

npm install @dupkey/mail

Example

import { Mailer, MailgunTransport, MessageSettings, Email } from '@dupkey/mail';
import * as Mailgun from 'mailgun-js';

const transport = new MailgunTransport(new Mailgun({
  apiKey: process.env.MAILGUN_KEY,
  domain: process.env.MAILGUN_DOMAIN
}));

export const mailer = new Mailer(
  transport,
  new Email('support'.concat('@', process.env.SENDMAIL_HOST), process.env.CLIENT_NAME),
  { client: process.env.CLIENT_NAME, uri: process.env.CLIENT_URI },
  (process.env.SENDMAIL === 'true')
);

const message = new Message(
  new Email('you@test.com', 'You'),
  'template',
  'subject',
  { data: 'foo' },
);

const response = async () => await mailer.send(message);

You will probably want to wire up your transport and mailer dependencies and then re-use throughout your app.

Build the TypeScript and JavaScript versions

npm run build

Run the tests

npm test

VS Code Debugging

Create a launch.json file in your .vscode folder with the following:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Mocha Tests",
      "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
      "args": [
        "--require", "ts-node/register",
        "-u", "tdd",
        "--timeout", "999999",
        "--colors", "--recursive",
        "${workspaceFolder}/test/**/*.ts"
      ],
      "internalConsoleOptions": "openOnSessionStart"
    }
  ]
}

In the debug tab (Ctrl+Shift+D) select "Mocha Tests" from the dropdown and then click "Start Debugging". Results will display in the console on the bottom of the VS Code.

Readme

Keywords

Package Sidebar

Install

npm i @dupkey/mail

Weekly Downloads

3

Version

1.1.0

License

MIT

Unpacked Size

22.7 kB

Total Files

30

Last publish

Collaborators

  • nicgene