# @optimiser/mailer

> Common Email package for microoptimiser and it's services. Tracks and sends the emails from the application.

Latest version **1.0.17** (published 2025-02-13) · ISC license · 0 weekly downloads

## Install

```sh
npm install @optimiser/mailer
pnpm add @optimiser/mailer
yarn add @optimiser/mailer
bun add @optimiser/mailer
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.17 |
| Published | 2025-02-13 |
| First published | 2023-10-23 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 9.1 KB |
| Known vulnerabilities | 0 (+15 in 1 direct dependencies) |
| Install scripts | no |
| Author | Optimiser |
| Maintainers | glotelligence |

## Links

- npm: https://www.npmjs.com/package/@optimiser/mailer
- npm.io page: https://npm.io/package/@optimiser/mailer

## Dependencies (3)

- [mongodb](https://npm.io/package/mongodb.md) ^5.7.0
- [nodemailer](https://npm.io/package/nodemailer.md) ^6.9.6
- [@aws-sdk/client-ses](https://npm.io/package/@aws-sdk/client-ses.md) ^3.429.0

## Recent versions

- 1.0.17 (latest) — 2025-02-13
- 1.0.16 — 2024-09-24
- 1.0.15 — 2024-09-20
- 1.0.14 — 2024-08-21
- 1.0.13 — 2024-08-20
- 1.0.12 — 2024-08-20
- 1.0.11 — 2024-05-23
- 1.0.10 — 2024-04-26
- 1.0.9 — 2024-04-24
- 1.0.8 — 2024-03-27
- 1.0.7 — 2024-03-27
- 1.0.6 — 2024-03-22
- 1.0.5 — 2024-03-20
- 1.0.4 — 2024-03-20
- 1.0.3 — 2024-03-20
- … 2 more at https://npm.io/package/@optimiser/mailer/versions

## README

# @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
```bash
npm install @optimiser/mailer
```

## Usage
First, require the `sendEmail` function from the library:

```javascript
const sendEmail = require('@optimiser/mailer');
```

## Sending an Email
```javascript
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
```bash
npm test
```

## Author
Optimiser

## License
ISC

---
_Source: https://npm.io/package/@optimiser/mailer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
