Custom Adapter
Create your own custom email adapter for VitNode.
Want to create your own email adapter? You can do it by implementing the EmailApiPlugin interface. This allows you to define how emails are sent in your application.
Usage
Create adapter
Here is your template for a custom email adapter.
import type { EmailApiPlugin } from "@vitnode/core/api/models/email";
export const MailerEmailAdapter = (): EmailApiPlugin => {};Add config
If you want to provide config for you adapter, you can do it like this:
import type { EmailApiPlugin } from "@vitnode/core/api/models/email";
export const MailerEmailAdapter = ({
host = "",
port = 587,
secure = false,
user = "",
password = "",
from = "",
}: {
from: string | undefined;
host: string | undefined;
password: string | undefined;
port?: number;
secure?: boolean;
user: string | undefined;
}): EmailApiPlugin => {};Add sendEmail() method
Implement the sendEmail() method to send emails using your custom logic. You can use any email sending library or service.
import type { EmailApiPlugin } from "@vitnode/core/api/models/email";
export const MailerEmailAdapter = ({
host = "",
port = 587,
secure = false,
user = "",
password = "",
from = "",
}: {
from: string | undefined;
host: string | undefined;
password: string | undefined;
port?: number;
secure?: boolean;
user: string | undefined;
}): EmailApiPlugin => {
return {
sendEmail: async ({ metadata, to, subject, html, replyTo, text }) => {},
};
};Publish to NPM
If you want to share your custom adapter with the community, you can publish it as an NPM package.
Example source code for NPM packages:
Make sure to follow best practices for package development and include proper documentation.