From 96ce85de3c3925673768874f4f92ad3ed770ef85 Mon Sep 17 00:00:00 2001 From: Krish Chothani <143370415+KrishChothani@users.noreply.github.com> Date: Fri, 3 Oct 2025 10:14:18 +0530 Subject: [PATCH 1/2] Add NodeMailer Email Integration --- .../NodeMailer Email Integration/.env.sample | 4 ++ .../NodeMailer Email Integration/README.md | 35 +++++++++++++ .../NodeMailer Email Integration/sendMail.js | 49 +++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 Integration/NodeMailer Email Integration/.env.sample create mode 100644 Integration/NodeMailer Email Integration/README.md create mode 100644 Integration/NodeMailer Email Integration/sendMail.js diff --git a/Integration/NodeMailer Email Integration/.env.sample b/Integration/NodeMailer Email Integration/.env.sample new file mode 100644 index 0000000000..8a8adca47b --- /dev/null +++ b/Integration/NodeMailer Email Integration/.env.sample @@ -0,0 +1,4 @@ +SMTP_HOST=smtp.gmail.com +SMTP_PORT=587 +SMTP_USER=your_email@gmail.com +SMTP_PASS=your_app_password diff --git a/Integration/NodeMailer Email Integration/README.md b/Integration/NodeMailer Email Integration/README.md new file mode 100644 index 0000000000..30cc1a9348 --- /dev/null +++ b/Integration/NodeMailer Email Integration/README.md @@ -0,0 +1,35 @@ +# 📧 NodeMailer Email Integration + +This snippet demonstrates how to send emails using **NodeMailer** in a Node.js environment. +It is useful for integrating ServiceNow or custom applications with external email providers via SMTP. + +## ✨ Features +- Uses environment variables for secure configuration. +- Sends both **plain text** and **HTML** emails. +- Provides error handling and logging. +- Ready for integration in ServiceNow-related workflows or external utilities. + +## 🛠️ Setup Instructions +1. Install dependencies: + ```bash + npm install nodemailer + + +2. 🔧 Configure Environment Variables + +```bash +SMTP_HOST=smtp.gmail.com +SMTP_PORT=587 +SMTP_USER=your_email@gmail.com +SMTP_PASS=your_app_password + +3. 📧 Sending Emails with NodeMailer + +You can use the provided snippet to quickly send emails: + +```javascript +// Import the sendMail function +const { sendMail } = require("./sendMail"); + +// Send an email +sendMail("receiver@example.com", "

Hello from NodeMailer

"); diff --git a/Integration/NodeMailer Email Integration/sendMail.js b/Integration/NodeMailer Email Integration/sendMail.js new file mode 100644 index 0000000000..6a2a7ed1f3 --- /dev/null +++ b/Integration/NodeMailer Email Integration/sendMail.js @@ -0,0 +1,49 @@ +/** + * NodeMailer Email Sending Snippet + * + * This snippet demonstrates how to send emails using NodeMailer. + * It uses environment variables for secure SMTP configuration. + * + * Usage: + * await sendMail("test@example.com", "

Hello from NodeMailer

"); + * + * @format + */ + +const nodemailer = require("nodemailer"); + +// Async function to send an email +const sendMail = async (emailId, htmlContent) => { + try { + // Create reusable transporter object using SMTP + const transporter = nodemailer.createTransport({ + host: process.env.SMTP_HOST, // e.g. "smtp.gmail.com" + port: process.env.SMTP_PORT || 587, + secure: false, // true for 465, false for other ports + auth: { + user: process.env.SMTP_USER, // your email address + pass: process.env.SMTP_PASS, // your email password or app password + }, + }); + + // Define the email options + const mailOptions = { + from: `"ServiceNow Integration" <${process.env.SMTP_USER}>`, // sender address + to: emailId, // list of receivers + subject: "ServiceNow Notification", // subject line + text: "This is a plain text body", // plain text body + html: htmlContent, // html body + }; + + // Send mail with defined options + const info = await transporter.sendMail(mailOptions); + + console.log("✅ Email sent successfully:", info.messageId); + return info; + } catch (error) { + console.error("❌ Error sending email:", error.message); + throw error; + } +}; + +module.exports = { sendMail }; From 32f15c0e1a315bbdcb29d999c6cc93cfc7af1cd1 Mon Sep 17 00:00:00 2001 From: Krish Chothani <143370415+KrishChothani@users.noreply.github.com> Date: Fri, 3 Oct 2025 10:21:10 +0530 Subject: [PATCH 2/2] Add NodeMailer Email Integration --- .../NodeMailer Email Integration/{ => Send Email}/.env.sample | 0 .../NodeMailer Email Integration/{ => Send Email}/README.md | 0 .../NodeMailer Email Integration/{ => Send Email}/sendMail.js | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename Integration/NodeMailer Email Integration/{ => Send Email}/.env.sample (100%) rename Integration/NodeMailer Email Integration/{ => Send Email}/README.md (100%) rename Integration/NodeMailer Email Integration/{ => Send Email}/sendMail.js (100%) diff --git a/Integration/NodeMailer Email Integration/.env.sample b/Integration/NodeMailer Email Integration/Send Email/.env.sample similarity index 100% rename from Integration/NodeMailer Email Integration/.env.sample rename to Integration/NodeMailer Email Integration/Send Email/.env.sample diff --git a/Integration/NodeMailer Email Integration/README.md b/Integration/NodeMailer Email Integration/Send Email/README.md similarity index 100% rename from Integration/NodeMailer Email Integration/README.md rename to Integration/NodeMailer Email Integration/Send Email/README.md diff --git a/Integration/NodeMailer Email Integration/sendMail.js b/Integration/NodeMailer Email Integration/Send Email/sendMail.js similarity index 100% rename from Integration/NodeMailer Email Integration/sendMail.js rename to Integration/NodeMailer Email Integration/Send Email/sendMail.js