Lucent provides email sending capabilities through pluggable adapters.
Configuration
export default defineConfig({
email: {
from: "noreply@your-domain.com",
provider: "nodemailer", // or "resend"
},
});
Email Adapters
Nodemailer (SMTP)
export default defineConfig({
email: {
from: "noreply@your-domain.com",
provider: "nodemailer",
nodemailer: {
host: process.env.SMTP_HOST,
port: 587,
secure: false,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS,
},
},
},
});
Environment:
SMTP_HOST=smtp.example.com
SMTP_USER=your-username
SMTP_PASS=your-password
SMTP_FROM="My App <noreply@example.com>"
Resend
export default defineConfig({
email: {
from: "noreply@your-domain.com",
provider: "resend",
resend: {
apiKey: process.env.RESEND_API_KEY,
},
},
});
Environment:
RESEND_API_KEY=re_1234567890abcdef
SMTP_FROM="My App <noreply@lucent.dev>"
Sending Emails
// Simple text email
await lucent.email.send({
to: "user@example.com",
subject: "Welcome",
text: "Welcome to our platform!",
});
// HTML email
await lucent.email.send({
to: "user@example.com",
subject: "Welcome",
html: "<h1>Welcome!</h1><p>Thanks for joining.</p>",
});
// With CC/BCC
await lucent.email.send({
to: "user@example.com",
cc: "admin@example.com",
bcc: "archives@example.com",
subject: "Notice",
text: "Please review this information.",
});
// Reply-to override
await lucent.email.send({
to: "user@example.com",
replyTo: "support@your-domain.com",
subject: "Help",
text: "How can we help?",
});
Queue Emails
For better performance in production, queue emails for background processing:
import { appQueue } from "./libs/queue";
import { SendEmailJob } from "./queues/EmailQueue";
await appQueue.addJob("email", "send-welcome", {
to: "user@example.com",
subject: "Welcome",
data: { name: "John" },
} as SendEmailJob);
Email Templates
Send templated emails with dynamic data:
// In your queue handler
await lucent.email.sendTemplate({
to: "user@example.com",
template: "welcome",
data: {
name: "John",
url: "https://your-domain.com/verify-email?token=xyz",
},
});
Verifying Email Configuration
Check if your email provider is properly configured:
const isValid = await lucent.email.verify();
console.log("Email provider configured:", isValid);