Skip to content

Email

Lucent provides email sending capabilities with support for SMTP and other providers.

Configuration

typescript
export default defineConfig({
  email: {
    provider: "smtp",
    from: "noreply@your-domain.com",
    smtp: {
      host: "smtp.example.com",
      port: 587,
      secure: false,
      auth: {
        user: process.env.SMTP_USER,
        pass: process.env.SMTP_PASS,
      },
    },
  },
});

Sending Emails

typescript
// Simple 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 from override
await lucent.email.send({
  to: "user@example.com",
  from: "support@your-domain.com",
  subject: "Help",
  text: "How can we help?",
});

Templates

typescript
// Send with template
await lucent.email.sendTemplate({
  to: "user@example.com",
  template: "welcome",
  data: {
    name: "John",
    url: "https://your-domain.com/verify",
  },
});

Queue Emails

For better performance, queue emails:

typescript
await lucent.email.queue({
  to: "user@example.com",
  subject: "Welcome",
  text: "Welcome!",
});

Email Providers

SMTP

typescript
email: {
  provider: 'smtp',
  smtp: {
    host: 'smtp.gmail.com',
    port: 587,
    secure: false,
    auth: { /* ... */ }
  }
}

SendGrid

typescript
email: {
  provider: 'sendgrid',
  sendgrid: {
    apiKey: process.env.SENDGRID_API_KEY
  }
}

Mailgun

typescript
email: {
  provider: 'mailgun',
  mailgun: {
    apiKey: process.env.MAILGUN_API_KEY,
    domain: 'your-domain.com'
  }
}

Released under the MIT License.