This package is a zero-config helper function to help you send emails in your nodejs apps using nodemailer 🚀🚀
- Gmail
- SMTP
- npm
npm i @xeuxdev/easymailer- pnpm
pnpm i @xeuxdev/easymailer-
using gmail
- you need the following environment variables
MAILER_GOOGLE_USER_EMAIL = "example@gmail.com"
MAILER_GOOGLE_USER_PASSWORD = "password"To get the password env, create an app password in your google account
-
using smtp
- you need the following environment variables
MAILER_SMTP_USERNAME = "your smtp username"
MAILER_SMTP_PASSWORD = "your smtp password"
MAILER_SMTP_HOST = "your smtp host"
MAILER_SMTP_PORT = "smtp host"you can get all the above env from your hosting account
- import the package into your server code
import { sendMail } from "@xeuxdev/easymailer"
or
const { sendMail } = require("@xeuxdev/easymailer")- call the function with the params
const response = await sendMail({
message: {},
transport: {},
})from-required- the name of the sendersubject-required- The subject of the emailhtml-required- The HTML version of the messageplainText-required- The plaintext version of the messageattachments-required- An array of attachment objectsto-optional- Comma separated list or an array of recipients email addresses that will appear on the To: fieldcc-optional- Comma separated list or an array of recipients email addresses that will appear on the Cc: fieldbcc-optional- Comma separated list or an array of recipients email addresses that will appear on the Bcc: field
service: -required- "gmail" | "smtp"secure: -optional- boolean - default: truepool: -optional- boolean - default: truegrouped: -optional- boolean - default: true
- you get a response object after calling the sendMail() function
{
message: string
status: "failed" | "successful"
}easymailer is compatible with all server codes, such as express, Nextjs API routes