@xeuxdev/easymailer
Version:
The mailer for your nodejs apps
107 lines (72 loc) • 2.39 kB
Markdown
- Gmail
- SMTP
- npm
```bash
npm i @xeuxdev/easymailer
```
- pnpm
```bash
pnpm i @xeuxdev/easymailer
```
- using gmail
- you need the following environment variables
```js
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
```js
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
```js
import { sendMail } from "@xeuxdev/easymailer"
or
const { sendMail } = require("@xeuxdev/easymailer")
```
- call the function with the params
```js
const response = await sendMail({
message: {},
transport: {},
})
```
- 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
- service: - required - "gmail" | "smtp"
- secure?: - optional - boolean - default: true
- pool?: - optional - boolean - default: true
- grouped?: - optional - boolean - default: true
- you get a response object after calling the **sendMail()** function
```js
{
message: string
status: "failed" | "successful"
}
```
mailer is compatible with all server codes, such as express, Nextjs API routes