npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mailsender-pro

v1.1.3

Published

An advanced npm package to generate and send OTPs via email for verification purposes with enhanced features.

Downloads

19

Readme

mailsender-pro

An advanced npm package to generate and send OTPs via email for verification purposes with enhanced features.

Features

  • Single Module with Zero Dependencies: A streamlined package with no external dependencies, making it easy to install and use.
  • Focus on Security: Designed to avoid RCE (Remote Code Execution) vulnerabilities and other common security issues.
  • Unicode Support: Handles Unicode characters, including emojis 💪, ensuring global compatibility.
  • Windows Support: Hassle-free installation and compatibility with Windows environments.
  • HTML and Plain Text Content: Supports both HTML content and plain text alternatives in emails.
  • Attachments and Embedded Images: Send emails with attachments and embedded images.
  • Secure Email Delivery: Utilizes TLS/STARTTLS for secure email transmission.
  • Support for Different Transport Methods: Flexible configuration for various email transport methods.
  • DKIM Signing: Optionally sign emails with DKIM for improved email deliverability and authenticity.
  • Custom Plugin Support: Extend functionality with custom plugins for manipulating email messages.
  • Sane OAuth2 Authentication: Integrates with OAuth2 for secure authentication.
  • Proxies for SMTP Connections: Supports SMTP connections through proxies.
  • ES6 Code: Utilizes modern JavaScript features for a clean and efficient codebase.
  • Autogenerated Email Test Accounts: Use Ethereal.email to generate test email accounts for development and testing.

Installation

To install the package, use npm:

npm install mailsender-pro

Usage
1. Check SMTP Server Details
Make sure you are using the correct SMTP server address and port for your email provider. Here’s a general guide:

Gmail: smtp.gmail.com, port 587 (STARTTLS) or port 465 (SSL)
SendGrid: smtp.sendgrid.net, port 587 (STARTTLS)
Mailgun: smtp.mailgun.org, port 587 (STARTTLS)
Amazon SES: email-smtp.us-east-1.amazonaws.com, port 587 (STARTTLS) or port 465 (SSL)
2. Update Configuration
Update your nodemailer configuration in index.js to use the correct SMTP server and port.

Example for SendGrid:
const transporter = nodemailer.createTransport({
  host: 'smtp.sendgrid.net', // SMTP server host
  port: 587, // Port for STARTTLS
  secure: false, // Use TLS/STARTTLS
  auth: {
    user: 'apikey', // This is the literal string 'apikey'
    pass: process.env.SENDGRID_API_KEY, // Your SendGrid API key
  },
});

Example for Mailgun:

const transporter = nodemailer.createTransport({
  host: 'smtp.mailgun.org',
  port: 587, // Port for STARTTLS
  secure: false, // Use TLS/STARTTLS
  auth: {
    user: process.env.MAILGUN_USER,
    pass: process.env.MAILGUN_PASS,
  },
});

Example for Amazon SES:

const transporter = nodemailer.createTransport({
  host: 'email-smtp.us-east-1.amazonaws.com',
  port: 587, // Port for STARTTLS
  secure: false, // Use TLS/STARTTLS
  auth: {
    user: process.env.AWS_SES_USER,
    pass: process.env.AWS_SES_PASS,
  },
});

3. Test Connectivity
To ensure your SMTP server is reachable, you can manually test the connection using tools like telnet or openssl:

For telnet:
telnet smtp.sendgrid.net 587

For openssl:
openssl s_client -connect smtp.sendgrid.net:465

# Generate OTP
Generate a One-Time Password (OTP):
const { generateOtp } = require('mailsender-pro');

const otp = generateOtp(6, { upperCaseAlphabets: true, specialChars: true });
console.log(`Generated OTP: ${otp}`);

# Encrypt OTP
Encrypt an OTP for secure storage:

const { encryptOtp } = require('mailsender-pro');

const encryptedOtp = encryptOtp('123456');
console.log(`Encrypted OTP: ${encryptedOtp}`);

# Decrypt OTP
Decrypt an OTP for verification:

const { decryptOtp } = require('mailsender-pro');

const decryptedOtp = decryptOtp('encryptedOtpString');
console.log(`Decrypted OTP: ${decryptedOtp}`);

# Validate OTP
Validate if the provided OTP matches the generated OTP:
Validate OTP
Validate if the provided OTP matches the generated OTP:

# Send OTP

Send an OTP via email:
const { sendOtp } = require('mailsender-pro');

const mailOptions = {
  to: '[email protected]',
  subject: 'Your OTP Code',
  otpLength: 6,
  customMessage: 'Your OTP code is {otp}. This code is valid for 10 minutes.',
  otpExpiresIn: 10,
  html: '<h1>Your OTP Code</h1><p>{otp}</p>',
  attachments: [
    {
      filename: 'test.txt',
      content: 'This is a test file'
    }
  ],
  embedImages: true
};

sendOtp('[email protected]', '123456', mailOptions)
  .then(() => console.log('OTP sent successfully!'))
  .catch(error => console.error('Error sending OTP:', error));


# Development
Running Tests
To run the tests for the package, use:

npm test

#Contributing
Fork the repository.
Create a new branch (git checkout -b feature/your-feature).
Make your changes.
Commit your changes (git commit -am 'Add new feature').
Push to the branch (git push origin feature/your-feature).
Create a new Pull Request.

#Authors
Hitank Shah - [email protected]
Maharshi Agrawal - [email protected]
Saksham Jain - [email protected]
Vedant Dongare - [email protected]