Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shiv-source/node-multi-mailer
A simple node.js module that exposes high-level API of Nodemailer and SendGrid.
https://github.com/shiv-source/node-multi-mailer
ejs ejs-templates email emailtemplate express html multimailer node-multi-mailer nodemailer sendgrid
Last synced: 1 day ago
JSON representation
A simple node.js module that exposes high-level API of Nodemailer and SendGrid.
- Host: GitHub
- URL: https://github.com/shiv-source/node-multi-mailer
- Owner: shiv-source
- License: mit
- Created: 2021-08-14T18:25:14.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-08-23T15:14:43.000Z (over 3 years ago)
- Last Synced: 2023-08-28T06:08:19.089Z (over 1 year ago)
- Topics: ejs, ejs-templates, email, emailtemplate, express, html, multimailer, node-multi-mailer, nodemailer, sendgrid
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/node-multi-mailer
- Size: 83 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-multi-mailer
![NPM Version](https://img.shields.io/npm/v/node-multi-mailer.svg?style=flat)
![NPM Downloads](https://img.shields.io/npm/dm/node-multi-mailer.svg)
![GitHub release](https://img.shields.io/github/release/shiv-source/node-multi-mailer)
![License](https://img.shields.io/github/license/shiv-source/node-multi-mailer)A simple node.js module that exposes high-level API of [Nodemailer](https://www.npmjs.com/package/nodemailer) and [SendGrid](https://www.npmjs.com/package/@sendgrid/mail).
# Installation
## Prerequisites
- Node.js >= 10.0.0
- A [Twilio SendGrid account](https://sendgrid.com/free?source=sendgrid-nodejs) for sending emails.## Install Package
The following recommended installation requires [npm](https://npmjs.org/). If you are unfamiliar with npm, see the [npm docs](https://npmjs.org/doc/). Npm comes installed with Node.js since node version 0.8.x, therefore, you likely already have it.
```sh
# With NPM
npm install --save node-multi-mailer
# With Yarn
yarn add node-multi-mailer
```
### Verify Sender Identity from SendGrid
Verify an email address or domain in the [Sender Authentication tab](https://app.sendgrid.com/settings/sender_auth/senders). Without this, you will receive a `403 Forbidden` response when trying to send mail.
# Examples
If you want to use an email template, then add an `email` folder in your project root directory and create a `login.ejs` file in the `email` folder. You can use any template name you want.
Add `attachment` folder in your root directory for sending an email with attachments.
```
Folder structure with mail template:
| +-- login.ejs
+-- attachments
| +-- myImage.png
| +-- resume.pdf
| +-- resume.docx
+-- node_modules
+-- index.js
+-- package.json
```If required, use this `login.ejs` file as an example template.
```html
Node-Multi-Mailer
Hey <%= firstName %> <%= lastName %>, Your OTP is <%= otp %>
```
## Implementation with NodeJs and SendGrid
```js
// Available options inside configuration objectconst multiMailer = require("node-multi-mailer");
const multiMailer = multiMailer.configuration({
senderEmail: "[email protected]",
senderName: "your business name", // Business Name
sendGridApiKey: SENDGRID_API_KEY, // SendGrid API Key
replyTo: "[email protected]", // optional parameter [ default = senderEmail ]
templateFolderPath: emailFolder, // optional parameter [ required for sending templates ]
attachmentFolderPath: attachmentFolder, // Optional parameter [ required for sending attachments]
});
```### A normal plain text email without any attachments
```js
// index.jsvar multiMailer = require("node-multi-mailer");
// Create a new instance of MultiMailer
multiMailer.configuration({
senderEmail: "[email protected]",
senderName: "your business name", // Business Name
sendGridApiKey: SENDGRID_API_KEY, // SendGrid API Key
replyTo: "[email protected]", // optional parameter [ default = senderEmail ]
});var RECEIVER_EMAIL = "[email protected]";
// To send a plain text email
multiMailer.SendGrid.sendTextEmail(
RECEIVER_EMAIL,
"Sending email from node-multi-mailer", // subject
"Thanks for sending email with node-multi-mailer" // body
);
```### A normal plain text email with attachments
```js
// index.js
var multiMailer = require("node-multi-mailer");
var path = require("path");var attachmentFolder = path.join(__dirname, "attachment"); // attachment folder path
let attachments = ["myImage.png", "resume.pdf", "resume.docx"]; // pass list of files you want to send with multiMailer
// Create a new instance of MultiMailer
multiMailer.configuration({
senderEmail: "[email protected]",
senderName: "your business name", // Business Name
sendGridApiKey: SENDGRID_API_KEY, // SendGrid API Key
replyTo: "[email protected]", // optional parameter [ default = senderEmail ]
templateFolderPath: emailFolder, // optional parameter [ required for sending templates ]
attachmentFolderPath: attachmentFolder, // Optional parameter [ required for sending attachments]
});var RECEIVER_EMAIL = "[email protected]";
// To send a plain text email
multiMailer.SendGrid.sendTextEmail(
RECEIVER_EMAIL,
"Sending email from node-multi-mailer", // subject
"Thanks for sending email with node-multi-mailer" // body
attachments,
);
```### A template email using EJS without attachments
```js
// index.jsvar multiMailer = require("node-multi-mailer");
var path = require("path");var emailFolder = path.join(__dirname, "email"); // template folder path
// Create a new instance of MultiMailer
multiMailer.configuration({
senderEmail: "[email protected]",
senderName: SENDER_NAME, // Business Name
sendGridApiKey: SENDGRID_API_KEY, // SendGrid API Key
replyTo: "[email protected]",
templateFolderPath: emailFolder,
});var RECEIVER_EMAIL = "[email protected]";
var data = {
fisrtName: "Shiv",
lastName: "Kumar",
otp: "123456",
};// To send a template email
multiMailer.SendGrid.sendEjsTemplateWithData(
RECEIVER_EMAIL,
"Sending email from node-multi-mailer", // subject
"login.ejs", // template name
data // template data
);
```### A template email using EJS with attachments
```js
// index.jsvar multiMailer = require("node-multi-mailer");
var path = require("path");var attachmentFolder = path.join(__dirname, "attachment"); // attachment folder path
var emailFolder = path.join(__dirname, "email"); // template folder path
let attachments = ["myImage.png", "resume.pdf", "resume.docx"]; // pass list of files you want to send with multiMailer
// Create a new instance of MultiMailer
multiMailer.configuration({
senderEmail: "[email protected]",
senderName: SENDER_NAME, // Business Name
sendGridApiKey: SENDGRID_API_KEY, // SendGrid API Key
replyTo: "[email protected]",
templateFolderPath: emailFolder,
attachmentFolderPath: attachmentFolder,
});var RECEIVER_EMAIL = "[email protected]";
var data = {
fisrtName: "Shiv",
lastName: "Kumar",
otp: "123456",
};// To send a template email
multiMailer.SendGrid.sendEjsTemplateWithData(
RECEIVER_EMAIL,
"Sending email from node-multi-mailer", // subject
"login.ejs", // template name
data // template data
attachments,
);
```## Implementation with ExpressJs
### A template email using EJS without attachments
```js
// index.jsvar express = require("express");
var multiMailer = require("node-multi-mailer");
var path = require("path");var attachmentFolder = path.join(__dirname, "attachment"); // attachment folder path
var emailFolder = path.join(__dirname, "email"); // template folder path
let attachments = ["myImage.png", "resume.pdf", "resume.docx"]; // pass list of files you want to send with multiMailer
// Create a new instance of MultiMailer
multiMailer.configuration({
senderEmail: "[email protected]",
senderName: SENDER_NAME, // Business Name
sendGridApiKey: SENDGRID_API_KEY, // SendGrid API Key
replyTo: "[email protected]",
templateFolderPath: emailFolder,
attachmentFolderPath: attachmentFolder,
});var app = express();
app.get("/", async (req, res) => {
var RECEIVER_EMAIL = "[email protected]";
var data = {
fisrtName: "Shiv",
lastName: "Kumar",
otp: "123456",
};// To send a template email
await multiMailer.SendGrid.sendEjsTemplateWithData(
RECEIVER_EMAIL,
"Sending email from node-multi-mailer", // subject
"login.ejs", // template name
data // template data
attachments,
);return res.send("Email sent");
});
```# Contributors
# License
[MIT](https://opensource.org/licenses/MIT)