OhMySMTP has rebranded to MailPace. This package will change name soon. If you're considering using it, you might want to wait for v2 to be published under fastify-mailpace
. This repository will be renamed.
See issue #7 for progress.
- Send emails
- Webhooks
- Inbound emails (coming soon)
$ yarn add fastify-ohmysmtp
# or
$ npm i fastify-ohmysmtp
Minimal example:
import Fastify from 'fastify'
import fastifyOhMySMTP from 'fastify-ohmysmtp'
const server = Fastify()
server.register(fastifyOhMySMTP, {
apiToken: 'my-api-token'
})
server.ohmysmtp.sendEmail({
from: '[email protected]',
to: '[email protected]',
subject: 'test',
htmlbody: '<h1>HTML Email</h1>'
})
You can provide the API token via the configuration or via the OHMYSMTP_API_TOKEN
environment variable.
You can enable reception of webhook events in the configuration object:
server.register(fastifyOhMySMTP, {
apiToken: 'my-api-token',
webhooks: {
// Where to attach the webhook endpoint (POST)
path: '/webhook',
/*
* An object map of handlers, where keys are the event types, listed here:
* https://docs.ohmysmtp.com/guide/webhooks#email-events
*
* Values are async handlers that take as argument:
* - The payload object of the webhook event
* - The request object from Fastify
* - The Fastify instance
*/
handlers: {
'email.spam': async (event, req, fastify) => {
req.log.info(event, 'Spam detected')
await fastify.ohmysmtp.sendEmail({
from: '[email protected]',
to: '[email protected]',
subject: 'Spam detected',
textbody: `Check event ${event.id} on OhMySMTP`
})
}
},
// You can pass additional Fastify route props here:
routeConfig: {
logLevel: 'warn'
}
}
})
MIT - Made with ❤️ by François Best
Using this package at work ? Sponsor me to help with support and maintenance.