@zcatalyst/mail
v0.0.3
Published
JavaScript SDK for Catalyst Mail - Email Sending
Maintainers
Readme
@zcatalyst/mail
JavaScript SDK for Catalyst Mail - Email Sending
Overview
The @zcatalyst/mail package provides JavaScript/TypeScript methods to send email through Catalyst Mail. Runs in Node.js (server-side) environments only.
Prerequisites
- A Catalyst project set up
- Sender email addresses configured in Mail settings
- Domain verification completed (if using custom domains)
- SMTP settings configured (if using external email client)
Installation
To install this package, simply type add or install @zcatalyst/mail using your favorite package manager:
npm install @zcatalyst/mailyarn add @zcatalyst/mailpnpm add @zcatalyst/mail
Getting Started
Import
The Catalyst SDK is modularized by Components.
To send a request, you only need to import the Mail:
// ES5 example
const { Mail } = require('@zcatalyst/mail');// ES6+ example
import { Mail } from '@zcatalyst/mail';Usage
To send a request, you:
- Create a Mail Instance.
- Call the Mail operation with input parameters.
const mail = new Mail();
const data = await mail.sendMail({
from_email: '[email protected]',
to_email: ['[email protected]', '[email protected]', '[email protected]'],
subject: 'Greetings from Zylker Corp!',
content: "Hello,We're glad to welcome you at Zylker Corp."
});Async/await
We recommend using await operator to wait for the promise returned by send operation as follows:
// async/await.
try {
const data = await mail.sendMail({
from_email: '[email protected]',
to_email: ['[email protected]', '[email protected]', '[email protected]'],
subject: 'Greetings from Zylker Corp!',
content: "Hello,We're glad to welcome you at Zylker Corp."
});
// process data.
} catch (error) {
// error handling.
} finally {
// finally.
}Error Handling
try {
const data = await mail.sendMail({
from_email: '[email protected]',
to_email: ['[email protected]', '[email protected]', '[email protected]'],
subject: 'Greetings from Zylker Corp!',
content: "Hello,We're glad to welcome you at Zylker Corp."
});
// process data.
} catch (error) {
const message = error.message;
const status = error.statusCode;
console.log({ message, status });
}Resources
Contributing
See CONTRIBUTING for more information on how to get started.
License
This SDK is distributed under the Apache License 2.0. See LICENSE file for more information.
