1.0.5 • Published 1 year ago

@clxmedia/xperience-mailjet-client v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Usage

This package provides a common interface to the MailJet API for the suite of Conversion Logix Xperience microservices and applications.

    const mjMessages:MailJetMessage[] = [
        ...array of messages in the MailJetMessage object format
    ];

    const mailJetClientConfig: MailJetClientConfig = { 
        credentials: { username: MAILJET_USERNAME, password: MAILJET_PASSWORD } 
    };

    const clxMjClient = new XperienceMailJetClient(mailJetClientConfig);

    const deliveryResults:MailDeliveryResponseItem[] = await clxMjClient.sendMessages(mjMessages);

The MailJetMessage is simply the MailJet.Email.SendParamsMessage interface provided by the node-mailjet package. However, the CustomId attribute is required in a MailJetMessage.

Passing in a CustomId for each email message is what allows for reporting back in the MailDeliveryResponseItem array which items were sent and which ones failed.

For Conversion Logix Xperience services, the CustomId is a randomly generated unique guid used for internal tracking and reporting. However, the XperienceMailJetClient does not really care what it is or what it represents so long as it is unique in the context of the provided MailJetMessage array.

The MailDeliveryResponseItem represents the result status of an email send attempt:

<MailDeliveryResponseItem>{ guid: '123456', success: true }

The sendMessages call returns a MailDeliveryResponseItem array.

Email Format Validation

The primary feature in this initial v1 of the XperienceMailJetClient is email address format checking. The default RegExp is extremely simple and aims to catch the vast majority of formatting issues. It does not take into account any domain/TLD checking nor is it a complete implementation of the RFC standard.

/^([a-z0-9])([a-z\.0-9_%\-\+\*'’!#`&\$/]*)@(.+)\.(.+)$/

The MailJetClientConfig lets you optionally provide your own email validation RegExp using the emailAddressRegex attribute in case the default implementation is not to your liking.

The XperienceMailJetClient will automatically check all recipients in each MailJetMessage using either the default emailAddressRegex or the one provided at runtime in the MailJetClientConfig. Each email address that fails the format validation check is removed from the corresponding recipient list.

The implications of this are as follows:

  • the removal of a Cc recipient allows the message to be sent, just without the specific Cc recipient
  • the removal of all Cc recipients allows the message to be send since Cc recipients are not required
  • the removal of some, but not all, To recipients allows the message to be sent since only 1 recipient is required
  • the removal of all To recipients means the message will get skipped and not sent to the MailJet API at all
    • the failure will be noted in the message's MailDeliveryResponseItem

Change Log

See Changelog for more information.

Author

Brandon Thompson

License

Licensed under the MIT License - see the LICENSE file for details.

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago