Package Exports
- @flightdev/email
- @flightdev/email/console
- @flightdev/email/resend
- @flightdev/email/sendgrid
- @flightdev/email/smtp
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: 'hello@example.com',
to: 'user@example.com',
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: 'noreply@example.com',
to: 'user@example.com',
subject: 'Hello',
text: 'Plain text content',
html: '<p>HTML content</p>',
});Multiple Recipients
await email.send({
from: 'noreply@example.com',
to: ['user1@example.com', 'user2@example.com'],
cc: ['manager@example.com'],
bcc: ['archive@example.com'],
subject: 'Team Update',
html: '<p>...</p>',
});Attachments
await email.send({
from: 'noreply@example.com',
to: 'user@example.com',
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: 'hello@example.com',
to: 'user@example.com',
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