Skip to main content

Email

Send emails through SMTP, SendGrid, or Amazon SES with template support.

Providers

ProviderConfiguration KeyDescription
smtpSMTP host/port/authStandard SMTP relay
sendgridSendGrid API keySendGrid transactional email
sesAWS credentialsAmazon Simple Email Service

Configuration

SMTP

messaging({
email: {
provider: "smtp",
host: "smtp.gmail.com",
port: 587,
secure: false,
auth: {
user: "your@gmail.com",
pass: "app-password",
},
from: "Your App <noreply@yourapp.com>",
},
});

SendGrid

messaging({
email: {
provider: "sendgrid",
apiKey: process.env.SENDGRID_API_KEY,
from: "noreply@yourapp.com",
},
});

Amazon SES

messaging({
email: {
provider: "ses",
region: "us-east-1",
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
from: "noreply@yourapp.com",
},
});

Sending Emails

Simple Email

await app.messaging.email.send({
to: "user@example.com",
subject: "Welcome!",
body: "<h1>Welcome to our platform</h1><p>Thanks for signing up.</p>",
});

With Attachments

await app.messaging.email.send({
to: "user@example.com",
subject: "Your Invoice",
body: "<p>Please find your invoice attached.</p>",
attachments: [
{
filename: "invoice.pdf",
content: pdfBuffer,
contentType: "application/pdf",
},
],
});

Multiple Recipients

await app.messaging.email.send({
to: ["alice@example.com", "bob@example.com"],
cc: ["manager@example.com"],
bcc: ["audit@example.com"],
subject: "Team Update",
body: "<p>Here is the weekly update.</p>",
});

Using Templates

// Register a template
app.messaging.email.registerTemplate("welcome", {
subject: "Welcome, {{name}}!",
body: `
<h1>Welcome, {{name}}!</h1>
<p>Thanks for joining {{appName}}.</p>
<a href="{{verifyUrl}}">Verify your email</a>
`,
});

// Send using the template
await app.messaging.email.sendTemplate("welcome", {
to: "alice@example.com",
data: {
name: "Alice",
appName: "My App",
verifyUrl: "https://myapp.com/verify?token=abc123",
},
});

API Reference

email.send(options): Promise<MessageResult>

OptionTypeRequiredDescription
tostring | string[]YesRecipient(s)
subjectstringYesEmail subject
bodystringYesHTML body
textstringNoPlain text body
fromstringNoOverride sender
ccstring | string[]NoCC recipients
bccstring | string[]NoBCC recipients
replyTostringNoReply-to address
attachmentsAttachment[]NoFile attachments

email.sendTemplate(name, options): Promise<MessageResult>

Send using a registered template.

email.registerTemplate(name, template): void

Register a reusable email template with {{variable}} placeholders.

REST API

curl -X POST http://localhost:3000/messaging/email \
-H "Content-Type: application/json" \
-H "Authorization: Bearer eyJhbGci..." \
-d '{
"to": "user@example.com",
"subject": "Hello",
"body": "<p>Hello from FluxKit!</p>"
}'

Response (200):

{
"messageId": "abc123",
"status": "sent",
"channel": "email",
"to": "user@example.com"
}