0.3.0 • Published 3 years ago

@maevia/mailer v0.3.0

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
3 years ago

About

A configurable tool for generating email parameters with an entity based api.

How to use

  1. First create a new Mail() instance, providing any default values as an object.

  2. Modify the instance properties directly to update the underlying data.

  3. Call getConfig() on the instance to get the formatted mail parameters.

    • By default the parameters returned are in the format required by nodemailer.
    • To override this implementation pass a custom formatOutput handler.

Example:

const mail = new Mail();

mail.to = 'test@domain.com';
mail.subject = 'Welcome to test';
mail.text = 'Message content here.';

const nodemailerParams = await mail.getConfig();

Setting default values

Default values can be provided to the Mail's constructor directly or passed to createMailFactory that returns a function that creates pre-loaded instances when called.

const createMail = createMailFactory({
  from: 'test@domain.com',
});

const mail: Mail = createMail();

console.log(mail.from); // test@domain.com

Handling email addresses

Internally, all email address are converted into a MailTargetDto instance which stores both the email and target name.

When accessing the targets directly, an array of MailTargetDto's will be returned. To have greater control of the returned targets call the instances getTargets.

When the parameters are generated, the address is returned as a string if no name was provided.

Remove targets by calling the instances removeTargets function.

Notes

  • Duplicates are removed on entry, keeping the most relevant.
  • Inputs are not validated on entry.
0.3.0

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.1

3 years ago