SimpleNS LogoDocs
Official Plugins

Nodemailer Gmail Plugin

Send emails with file attachments and inline images via Gmail SMTP using Nodemailer


What is Nodemailer Gmail Plugin

The @simplens/nodemailer-gmail plugin enables email delivery through Gmail SMTP (or any compatible SMTP server) using Nodemailer, with built-in support for file attachments and inline base64 image extraction.

How It Works

Before calling the plugin, SimpleNS Core handles template variable substitution ({{variable}}) and resolves any file attachments into buffer or stream payloads. When the plugin's send() method runs:

  1. Receives the pre-rendered notification payload and resolved attachments
  2. Validates attachment size, count, and MIME type rules (and extracts any inline base64 <img> tags in HTML bodies into CID attachments)
  3. Auto-detects whether the message body is HTML or plain text
  4. Sends the email via Gmail SMTP and classifies any SMTP or validation errors as retryable or non-retryable

Gmail has sending limits: ~500 emails/day for regular accounts and ~2,000/day for Google Workspace.


Installation & Configuration

  1. Open Dashboard → Plugins (/plugins).
  2. Install @simplens/nodemailer-gmail from the plugin catalog.
  3. Add a provider instance, enter your EMAIL_USER and EMAIL_PASS (Gmail App Password) plus any optional SMTP or attachment settings, and configure rate limits.
  4. Assign the provider as the default (or fallback) for the email channel in Channel Routing.

Credentials are encrypted at rest in MongoDB and hot-reloaded across all workers and processors via Redis Pub/Sub.

Required Credentials

KeyDescription
EMAIL_USERYour Gmail address
EMAIL_PASSGmail App Password (not your regular password)

Optional Config (options)

KeyDefaultDescription
EMAIL_HOSTsmtp.gmail.comSMTP host
EMAIL_PORT587SMTP port (use 465 for SSL)
EMAIL_FROMEMAIL_USERSender email address
ATTACHMENT_ENABLEDtrueEnable or disable file attachments for this provider instance ("false" rejects attachments non-retryably)
ATTACHMENT_MAX_FILE_SIZE18MBMax size per file and cumulative total (e.g., 18MB or bytes)
ATTACHMENT_MAX_COUNT10Maximum number of file attachments per email
ATTACHMENT_ALLOWED_MIME_TYPES(see defaults below)Comma-separated string or array of allowed MIME types

Rate Limit Defaults

KeyDefaultDescription
maxTokens500Max tokens in bucket
refillRate500Tokens refilled per interval
refillIntervaldayRefill period (second, minute, hour, day)

File Attachments

@simplens/nodemailer-gmail supports file attachments out of the box, with guardrails designed around Gmail's 25 MB SMTP message limit.

Transport & Validation Rules

  • Resolved payloads required: SimpleNS Core downloads each attachment into a buffer or stream before calling the plugin. Raw url paths are not accepted by Nodemailer and fail non-retryably.
  • Disabled guard: If ATTACHMENT_ENABLED is set to "false", any notification containing attachments fails immediately with a non-retryable error.

Baseline Defaults & Limits

LimitDefaultNotes
EnabledtrueControlled via ATTACHMENT_ENABLED
Max File Size18 MB (18 * 1024 * 1024 bytes)Applies per file AND cumulatively across all file attachments + inline base64 images (keeps total MIME size under Gmail's 25 MB limit after ~33% base64 overhead)
Max Attachment Count10Maximum file attachments per email

Inline Base64 Images (HTML Emails)

When an HTML email body contains inline data URIs (<img src="data:image/...;base64,...">), the plugin automatically extracts them and converts them into CID attachments (src="cid:...") so email clients render them reliably instead of blocking inline data URIs.

  • Allowed formats: Raster images only (png, jpeg/jpg, gif, webp). image/svg+xml is rejected.
  • Max inline images: 5 per email
  • Max size per inline image: 2 MB
  • Max cumulative inline images: 5 MB (and counted toward the 18 MB total message attachment budget)

Gmail App Password Setup

You cannot use your regular Gmail password. You must generate an App Password.

Enable 2-Factor Authentication

Go to your Google Account security settings and enable 2FA.

Generate App Password

Navigate to App Passwords and create a new password for "Mail".

Use the App Password

Set EMAIL_PASS to the generated 16-character password in Dashboard → Plugins (/plugins).


Notification Payload

Use Payload Studio in the Admin Dashboard to inspect the exact schema for your installed instance.

{
  "request_id": "uuid-v4",
  "client_id": "uuid-v4",
  "channel": ["email"],
  "webhook_url": "https://your-app.com/webhooks/simplens",
  "recipient": {
    "user_id": "user-123",
    "email": "recipient@example.com"
  },
  "content": {
    "email": {
      "subject": "Welcome!",
      "message": "Hello {{name}}, your order #{{order_id}} is confirmed."
    }
  },
  "variables": {
    "name": "John",
    "order_id": "12345"
  }
}
{
  "request_id": "uuid-v4",
  "client_id": "uuid-v4",
  "channel": ["email"],
  "webhook_url": "https://your-app.com/webhooks/simplens",
  "recipient": {
    "user_id": "user-123",
    "email": "recipient@example.com"
  },
  "content": {
    "email": {
      "subject": "Your Invoice",
      "message": "<p>Hi {{name}}, your invoice is attached.</p>",
      "attachments": [
        {
          "id": "file_abc123",
          "filename": "invoice.pdf",
          "mime_type": "application/pdf",
          "size": 48210,
          "hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
        }
      ]
    }
  },
  "variables": {
    "name": "John"
  }
}

Error Classification & Features

SMTP 5xx responseCode errors, EAUTH / EENVELOPE failures, and attachment validation errors are classified as non-retryable (retryable: false), allowing SimpleNS to immediately trigger fallback routing when configured.

FeatureDescription
HTML & Plain TextAuto-detects content type
File AttachmentsSupports buffer/stream attachments up to 18 MB total and 10 files by default
Inline Base64 CID ImagesAutomatically extracts raster data:image/* tags in HTML to cid: attachments
Rate LimitingToken bucket defaulting to 500 emails/day
Smart RetryClassifies SMTP 5xx, EAUTH, EENVELOPE, and attachment validation errors as non-retryable
Any SMTP ServerWorks with Gmail or any custom SMTP host/port

On this page