@xenterprises/fastify-xemail
v1.0.2
Published
Fastify plugin for SendGrid email integration.
Readme
@xenterprises/fastify-xemail
Fastify plugin for SendGrid email integration.
Features
- Send simple emails
- Send template-based emails
- Send emails with attachments
- Bulk sending (simple and personalized)
- Email validation
- Contact management (add, search, delete)
- List management
Installation
npm install @xenterprises/fastify-xemailUsage
import Fastify from 'fastify';
import xEmail from '@xenterprises/fastify-xemail';
const fastify = Fastify();
await fastify.register(xEmail, {
apiKey: process.env.SENDGRID_API_KEY,
fromEmail: '[email protected]'
});
// Usage example
fastify.get('/send-welcome', async (request, reply) => {
const { email, name } = request.query;
await fastify.xEmail.send(
email,
'Welcome!',
`<h1>Welcome ${name}!</h1>`,
`Welcome ${name}!`
);
return { success: true };
});API
fastify.xEmail.send(to, subject, html, text, extraOptions)
Send a single email.
fastify.xEmail.sendTemplate(to, subject, templateId, dynamicData, extraOptions)
Send an email using a SendGrid dynamic template.
fastify.xEmail.sendWithAttachments(to, subject, html, attachments)
Send an email with attachments.
fastify.xEmail.validate(email)
Validate an email address using SendGrid's Validation API.
License
ISC
