1.0.10 • Published 14 days ago
@optimiser/mailer v1.0.10
@optimiser/mailer
Common Email package for microoptimiser and its services. Tracks and sends the emails from the application.
Features
- Sends emails using AWS Simple Email Service (SES).
- Automatically logs email send attempts to a MongoDB database.
- Email open tracking via a tracking pixel.
- Configuration validation for AWS credentials and email payload.
Installation
npm install @optimiser/mailer
Usage
First, require the sendEmail
function from the library:
const sendEmail = require('@optimiser/mailer');
Sending an Email
const config = {
credentials: {
accessKeyId: 'your-aws-access-key-id',
secretAccessKey: 'your-aws-secret-access-key'
},
region: 'your-aws-region'
};
const payload = {
from: 'sender@example.com',
to: 'recipient@example.com',
subject: 'Hello World',
html: '<p>This is a test email.</p>',
... // Other params specific to nodemailer
};
const params = {
companyID: 'your-company-id',
PROJECT_DOMAIN: 'your-project-domain',
db: 'your-mongodb-instance'
};
const sendEmailResponse = await sendEmail(config, payload, params);
console.log(sendEmailResponse);
Configuration Validation
The library validates the AWS credentials and email payload before attempting to send the email. If any required field is missing, it will throw an error.
Email Open Tracking
The library appends a tracking pixel to the HTML body of the email to track email opens.
Email Logging
The library logs email send attempts to a MongoDB database, including the status (success or error), and the response from the AWS SES.
Running Tests
npm test
Author
Optimiser
License
ISC