oss-mailer
v1.0.0
Published
Client SDK for the oss-mailer self-hosted email routing service
Maintainers
Readme
oss-mailer
Client SDK for the oss-mailer self-hosted email routing service.
Install
npm install oss-mailerUsage
Send a transactional email
import { createMailerClient } from 'oss-mailer'
const mailer = createMailerClient({
url: process.env.MAILER_URL!,
apiKey: process.env.MAILER_API_KEY!,
})
await mailer.sendMail({
category: 'update',
to: '[email protected]',
subject: 'Your weekly digest',
props: { html: preRenderedHtml },
})Send a magic link email
await mailer.sendMail({
category: 'magic_link',
to: '[email protected]',
subject: 'Sign in to your account',
props: { url: 'https://app.example.com/auth/verify?token=abc123' },
})NextAuth v5 email provider
import { MailerEmailProvider } from 'oss-mailer/nextauth'
// In your auth.ts:
providers: [
MailerEmailProvider({
mailerUrl: process.env.MAILER_URL!,
apiKey: process.env.MAILER_API_KEY!,
from: '[email protected]',
appName: 'My App',
})
]Environment variables (set in your app, not in this package)
| Variable | Description |
|---|---|
| MAILER_URL | Base URL of your deployed oss-mailer instance |
| MAILER_API_KEY | API key configured on the mailer service |
Error handling
import { createMailerClient, isMailerError } from 'oss-mailer'
try {
await mailer.sendMail(...)
} catch (e) {
if (isMailerError(e)) {
console.error(e.code, e.detail)
}
}