Nodemailer Email Sender

This npm package offers a straightforward utility function for sending emails through Nodemailer.

Download Now

GitHub NPM Package

Installation

This project supports the following languages. See the language-specific guide:

  • JavaScript
  • TypeScript
  • Python (not published)

Usage

  1. Import the Function:
    • JavaScript
    • npm install send-email-util
    • Python
    • pip install send-email-util
    • TypeScript
    • npm install send-email-util
  2. Send Emails:
    • JavaScript
    • import sendEmail from "send-email-util/javascript/sendEmail.js"; // Example usage const emailObject = { mail: "recipient@example.com", subject: "Subject of the email", message: "Content of the email", }; await sendEmail(emailObject);
    • Python
    • from send-email-util.python.send_email import send_email email_object = { 'mail': 'recipient@example.com', 'subject': 'Subject of the email', 'message': 'Content of the email', } send_email(email_object)
    • TypeScript
    • import sendEmail from "send-email-util/typescript/sendEmail.js"; const emailObject = { mail: "recipient@example.com", subject: "Subject of the email", message: "Content of the email", }; await sendEmail(emailObject);

Note: Replace "recipient@example.com" with the recipient's email address, "Subject of the email" with the desired subject line, and "Content of the email" with the email body content.

Configuration

This package relies on environment variables for SMTP configuration. Ensure you have these set:

  • SMTP_HOST: SMTP server hostname
  • SMTP_PORT: SMTP server port
  • SMTP_USER: SMTP username
  • SMTP_PASS: SMTP password

You can define these environment variables in a .env file or directly within your deployment environment.

🚀Future plans/ideas

  • Add support for languages like Python, TypeScript, and GoLang
  • Input Validation: Implement rigorous validation to prevent injection attacks and ensure only valid input is accepted
  • Credential Management: Shift away from hardcoded credentials towards secure storage methods like environment variables
  • Error Handling: Implement robust error handling to prevent leakage of sensitive information

Build Logs

1.0.0: This version included just the package with JavaScript support.

1.5.0: Added support for languages like TypeScript and Python.

1.6.0: adding input validation for the email address, subject, and message.

Contribution

If you have any issue or have an idea which can improve this, feel free to raise a PR or open a new issue.

Contact me

Abhishek kumar (Twitter): @abhirajabhi312