Usage

Usage

To use the easymailer package in your server code

import the package into your server side code

ESM
import { sendMail } from "@xeuxdev/easymailer"
CJS
const { sendMail } = require("@xeuxdev/easymailer")

call the function and pass the parameters

const response = await sendMail({
  message: {},
  transport: {},
})

Note: There are two main parameters - message and transport

message

The message parameter contains props regarding the message / email

  • from - required - the name of the sender.
  • subject - required - The subject of the email.
  • html - required - The HTML version of the message.
  • plainText - required - The plaintext version of the message.
  • attachments - required - An array of attachment objects.
  • to - optional - Comma separated list or an array of recipients email addresses that will appear on the To: field.
  • cc - optional - Comma separated list or an array of recipients email addresses that will appear on the Cc: field.
  • bcc - optional - Comma separated list or an array of recipients email addresses that will appear on the Bcc: field.

transport

The transport parameter contains props regarding the sending of the email

  • service: - required - gmail or smtp
  • secure: - optional - boolean - default: true
  • pool: - optional - boolean - default: true
  • grouped: - optional - boolean - default: true

Response

you get a response object after calling the sendMail() function

{
  message: "string"
  status: "failed" | "successful"
}

Supported Transports

  • Gmail
  • SMTP

Compatibility

Easymailer is compatible with all nodejs server environments, such as

  • expressjs
  • Nextjs API routes