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 theTo
: field.cc
-optional
- Comma separated list or an array of recipients email addresses that will appear on theCc
: field.bcc
-optional
- Comma separated list or an array of recipients email addresses that will appear on theBcc
: field.
transport
The transport parameter contains props regarding the sending of the email
service
: -required
-gmail
orsmtp
secure
: -optional
-boolean
- default: truepool
: -optional
-boolean
- default: truegrouped
: -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