Parse Server API Mail Adapter
The `parse-server-api-mail-adapter` provides a universal email solution for Parse Server, enabling it to send emails via any third-party REST API. It supports dynamic templates, localization, and includes out-of-the-box integrations for services like AWS SES, Mailgun, and ZeptoMail, along with a custom API option. The current stable version is 5.0.5, with frequent maintenance releases for security updates and occasional minor/major releases for new features or Node.js version support. Its key differentiators include its extensibility to any REST API-based mail service, built-in templating, and full localization support, making it a flexible choice compared to adapters tied to specific providers. It ships with TypeScript definitions, enhancing developer experience for TypeScript users.
Common errors
-
Error: Node.js version 18.x.x is not supported by parse-server-api-mail-adapter@5.x.x
cause Attempting to run the adapter version 5.x.x on an unsupported Node.js runtime (Node 18).fixUpgrade your Node.js environment to version 20, 22, or 24. For example, using NVM: `nvm install 20 && nvm use 20`. -
TypeError: Cannot read properties of undefined (reading 'client')
cause The mail client (e.g., Mailgun client) or its configuration object (`api.mailgun.client`) is not correctly initialized or passed to the adapter options.fixEnsure `mailgun.js` or your chosen mail client is correctly imported, initialized with necessary API keys, and the resulting client instance is passed to the adapter configuration under `options.api.[providerName].client`. -
MailAdapter: email verification template not found at path: path/to/templates/email_verification.html
cause The specified `pathHtml` or `pathPlainText` for an email template (like `emailVerification` or `passwordReset`) does not point to an existing file.fixVerify that the template files exist at the exact paths specified in the `templates` object within the `emailAdapter` configuration. Ensure file permissions allow the Parse Server process to read them. -
Error: Mailgun API call failed: 401 Unauthorized
cause The API key or domain configured for the Mailgun provider is incorrect or invalid.fixDouble-check your `MAILGUN_API_KEY` and `MAILGUN_DOMAIN` environment variables or hardcoded values in the adapter configuration against your Mailgun account details.
Warnings
- breaking Version 5.0.0 removed support for Node.js 18. Your Parse Server environment must be running Node.js 20, 22, or 24. Subsequent minor releases fix `package-lock.json` sync and correct engine specification, but the core Node.js requirement remains.
- breaking Version 4.0.0 removed support for Node.js 14 and 16. Deployments on these older Node.js versions will fail or encounter unexpected behavior.
- gotcha The repository was transferred to the Parse Platform Organization on May 15, 2022. Direct GitHub references or cloned repositories with outdated remotes will need to be updated.
- gotcha Security vulnerability fixes have been released in recent versions for underlying dependencies like `undici`, `tar`, `npm`, `lodash`, and `@babel/traverse`. Running older versions may expose your application to known vulnerabilities.
- gotcha When configuring a custom API, ensure the `send` function correctly handles the expected payload and returns a Promise, as Parse Server relies on this contract for email delivery.
Install
-
npm install parse-server-api-mail-adapter -
yarn add parse-server-api-mail-adapter -
pnpm add parse-server-api-mail-adapter
Imports
- ApiPayloadConverter
const { ApiPayloadConverter } = require('parse-server-api-mail-adapter');import { ApiPayloadConverter } from 'parse-server-api-mail-adapter'; - ApiMailAdapter
import { ApiMailAdapter } from 'parse-server-api-mail-adapter';import ApiMailAdapter from 'parse-server-api-mail-adapter';
- MailAdapterOptions
import { MailAdapterOptions } from 'parse-server-api-mail-adapter';import type { MailAdapterOptions } from 'parse-server-api-mail-adapter';
Quickstart
import ParseServer from 'parse-server';
import Mailgun from 'mailgun.js';
import formData from 'form-data';
const mailgun = new Mailgun(formData);
const mailgunClient = mailgun.client({ username: 'api', key: process.env.MAILGUN_API_KEY ?? '' });
const mailgunDomain = process.env.MAILGUN_DOMAIN ?? 'your-mailgun-domain.com';
// Basic Parse Server setup
const server = new ParseServer({
databaseURI: process.env.DATABASE_URI ?? 'mongodb://localhost:27017/dev',
cloud: __dirname + '/cloud/main.js', // Or wherever your cloud code is
appId: process.env.APP_ID ?? 'myAppId',
masterKey: process.env.MASTER_KEY ?? 'myMasterKey',
serverURL: process.env.SERVER_URL ?? 'http://localhost:1337/parse',
publicServerURL: process.env.PUBLIC_SERVER_URL ?? 'http://localhost:1337/parse',
// Configure the Mail Adapter
emailAdapter: {
module: 'parse-server-api-mail-adapter',
options: {
sender: process.env.MAIL_SENDER ?? 'noreply@example.com',
templates: {
passwordReset: {
subject: 'Reset Your Password',
pathPlainText: 'path/to/templates/password_reset.txt',
pathHtml: 'path/to/templates/password_reset.html'
},
emailVerification: {
subject: 'Verify Your Email',
pathPlainText: 'path/to/templates/email_verification.txt',
pathHtml: 'path/to/templates/email_verification.html'
}
},
// Example for Mailgun provider
api: {
mailgun: {
domain: mailgunDomain,
client: mailgunClient,
options: {
// Custom options for Mailgun API calls
}
}
}
// Other API providers like AWS SES, ZeptoMail or custom API would be configured here
}
}
});
// To run Parse Server (for example in index.js)
// const app = express();
// app.use('/parse', server.app);
// const port = process.env.PORT || 1337;
// app.listen(port, () => console.log(`Parse Server running on port ${port}.`));