0.5.0 • Published 3 years ago

@packmate/mail v0.5.0

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

@packmate/mail

Send emails from Node.js (via SendGrid) with optional test runs.

Installation

npm install @packmate/mail

The Configuration Function

Usage

const configureSend = require('@packmate/mail')

Syntax

configureSend(options)

Arguments

NameTypeDescription
optionsObject: ConfigureOptionsConfiguration for all mailers.

Returns

TypeDescription
Function: SendA send function for sending mail.

Exceptions

Throws a standard Error if:


The ConfigureOptions Object

AttributeTypeDescription
dryBoolean (default: false)If set to true, generated mailers will always perform dry runs. This overrides the individual mailer options.
keyStringA SendGrid API key to use when sending mail.
mailObject (default: @sendgrid/mail)A SendGrid mail implementation.
senderObject: SenderA default sender to send messages from.

The Sender Object
AttributeTypeDescription
nameStringThe name of the sender.
emailStringThe email of the sender.

The Send Function

Syntax

send(type, messages, options)

Arguments

NameTypeDescription
typeStringA name for the type of mail being sent, used for logging.
messageObject:Message | Array [Object: Message]One or more message objects representing the message(s) to be sent.
optionsObject: OptionsConfiguration for this mailer.

Returns

TypeDescription
Object: PromiseA promise to send mail via the SendGrid mail implementation.

Exceptions

Throws a standard Error if:

  • No type is present.
  • No message is present.
  • The message object does not contain all required properties.
  • The options object does not contain all required properties.

Effects

  • Mail will be sent via the SendGrid mail implementation.
  • Information will be logged using log function provided to the mailer.

During a live run:

  • The default sender will be BCC'd on all messages.

During a dry run:

  • All mail will be redirected to the default sender.
  • Debugging information including the original recipient(s) will be added to the template data.

The Message Object

AttributeTypeDescription
attachment (optional)Object: AttachmentAn attachment to send with the email.
data (optional)Object (optional)Template data to use in the dynamic template.
template_idStringA SendGrid dynamic template ID.
toObject: Person | Array [Object: Person]One or more people to send this message to.
bccObject: Person | Array [Object: Person]One or more people to blind-copy on this message.

The Attachment Object
AttributeTypeDescription
filenameStringThe filename for the attachment.
contentStringA Base64 encoded string containing the file data.

The Person Object
AttributeTypeDescription
emailsArrayA list of one or more emails to use for this person.
greetingStringA greeting to be used when addressing this person (i.e. Dear [greeting],)
nameStringThe person's full name.

The Options Object

AttributeTypeDescription
dryBoolean (default: false)Whether or not to perform a dry run. This can be overridden in the ConfigureOptions.
logFunction: LogA log function which will be used to log mailing information.

The Log Function

A function for logging information.

The function should include an .error() property for logging errors.

Example Syntax
function log(value) {
  console.log(value)
}

log.error = (error) => {
  console.error(error)
}
0.5.0

3 years ago

0.4.1

3 years ago

0.4.2

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.4

3 years ago

0.2.1

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.0

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.0

3 years ago

0.1.1

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago