@travetto/email
v5.0.13
Published
Email transmission module.
Downloads
234
Readme
Email transmission module.
Install: @travetto/email
npm install @travetto/email
# or
yarn add @travetto/email
A standard API for sending and rendering emails. The mail transport must be defined to allow for mail to be sent properly. Out of the box, the only transport available by default is the NullTransport which will just drop emails. The structure of the API is derived from nodemailer, but is compatible with any library that can handle the EmailOptions input.
To expose the necessary email transport, the following pattern is commonly used:
Code: Declaring the null transport for development
import { InjectableFactory } from '@travetto/di';
import { NullTransport } from '@travetto/email';
class Config {
@InjectableFactory()
static getTransport() {
return new NullTransport();
}
}
Given the amorphous nature of transports, the transport
field in MailConfig is open for any configuration that you may want there. Additionally, the templating engine is optional. The code will only fail if you attempt to send a templated email without declaring the dependency first.
Sending Compiled Templates
By design, sending an email requires the sender to specify the html, text optionally, and subject. To integrate with other tools, the framework also has the ability to send an email as a set of templates, based off a single key. The module will look for:
resources/<key>.compiled.html
resources/<key>.compiled.text
resources/<key>.compiled.subject
With.html
being the only required field. The Email Compilation Support module supports this format, and will generate files accordingly. Also, note that<key>
can include slashes, allowing for nesting folders.