v1.4.3These docs are for laramail v1.4.3. View changelog

SMTP Provider

The SMTP provider uses Nodemailer under the hood and is included with the base laramail package. No additional installation is required.

Installation

Included with laramail -- no extra dependencies needed.

Configuration

Mail.configure({
  default: 'smtp',
  from: { address: 'noreply@example.com', name: 'My App' },
  mailers: {
    smtp: {
      driver: 'smtp',
      host: 'smtp.example.com',
      port: 587,
      auth: { user: 'username', pass: 'password' },
    },
  },
});

Connection Pooling

Enable connection pooling for high-volume sending. The pool reuses SMTP connections instead of creating a new one for each email.

Mail.configure({
  default: 'smtp',
  from: { address: 'noreply@example.com', name: 'My App' },
  mailers: {
    smtp: {
      driver: 'smtp',
      host: 'smtp.example.com',
      port: 587,
      auth: { user: 'username', pass: 'password' },
      pool: true,
      maxConnections: 5,   // default: 5
      maxMessages: 100,     // default: 100
    },
  },
});
OptionTypeDefaultDescription
poolbooleanfalseEnable connection pooling
maxConnectionsnumber5Maximum simultaneous SMTP connections
maxMessagesnumber100Maximum messages per connection before reconnecting

SmtpProvider Extras

The SmtpProvider exposes an additional verify() method that lets you check whether the SMTP connection is valid before sending emails.

  • verify(): Promise<boolean> -- Returns true if the connection is valid.
import { SmtpProvider } from 'laramail';

const smtp = new SmtpProvider({
  driver: 'smtp',
  host: 'smtp.example.com',
  port: 587,
  auth: { user: 'user', pass: 'pass' },
});

const isValid = await smtp.verify(); // true or false