@flightdev/email
v0.0.7
Published
Email adapters for Flight Framework - Resend, SendGrid, SMTP
Maintainers
Readme
@flightdev/email
Email sending for Flight Framework. Unified API for multiple email providers.
Table of Contents
Installation
npm install @flightdev/emailQuick Start
import { createEmail } from '@flightdev/email';
import { resend } from '@flightdev/email/resend';
const email = createEmail(resend({
apiKey: process.env.RESEND_API_KEY,
}));
await email.send({
from: '[email protected]',
to: '[email protected]',
subject: 'Welcome!',
html: '<h1>Welcome to our platform!</h1>',
});Adapters
Resend
Modern email API with React support.
import { resend } from '@flightdev/email/resend';
const adapter = resend({
apiKey: process.env.RESEND_API_KEY,
});Postmark
Transactional email service.
import { postmark } from '@flightdev/email/postmark';
const adapter = postmark({
serverToken: process.env.POSTMARK_SERVER_TOKEN,
});SendGrid
Scalable email delivery.
import { sendgrid } from '@flightdev/email/sendgrid';
const adapter = sendgrid({
apiKey: process.env.SENDGRID_API_KEY,
});AWS SES
Amazon Simple Email Service.
import { ses } from '@flightdev/email/ses';
const adapter = ses({
region: 'us-east-1',
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
},
});SMTP
Any SMTP server.
import { smtp } from '@flightdev/email/smtp';
const adapter = smtp({
host: 'smtp.example.com',
port: 587,
secure: false,
auth: {
user: 'username',
pass: 'password',
},
});Sending Emails
Basic Email
await email.send({
from: '[email protected]',
to: '[email protected]',
subject: 'Hello',
text: 'Plain text content',
html: '<p>HTML content</p>',
});Multiple Recipients
await email.send({
from: '[email protected]',
to: ['[email protected]', '[email protected]'],
cc: ['[email protected]'],
bcc: ['[email protected]'],
subject: 'Team Update',
html: '<p>...</p>',
});Attachments
await email.send({
from: '[email protected]',
to: '[email protected]',
subject: 'Your Invoice',
html: '<p>Please find your invoice attached.</p>',
attachments: [
{
filename: 'invoice.pdf',
content: pdfBuffer,
contentType: 'application/pdf',
},
],
});Templates
React Email (with Resend)
import { render } from '@react-email/render';
import { WelcomeEmail } from './emails/welcome';
const html = render(<WelcomeEmail username="John" />);
await email.send({
from: '[email protected]',
to: '[email protected]',
subject: 'Welcome!',
html,
});API Reference
email.send(options)
| Option | Type | Description |
|--------|------|-------------|
| from | string | Sender email address |
| to | string \| string[] | Recipient(s) |
| subject | string | Email subject |
| html | string | HTML body |
| text | string | Plain text body |
| cc | string[] | CC recipients |
| bcc | string[] | BCC recipients |
| replyTo | string | Reply-to address |
| attachments | Attachment[] | File attachments |
Attachment
| Property | Type | Description |
|----------|------|-------------|
| filename | string | File name |
| content | Buffer \| string | File content |
| contentType | string | MIME type |
License
MIT
