UNPKG

send-email-utility-function

Version:

A simple utility for sending emails using Node.js and Nodemailer.

63 lines (43 loc) β€’ 1.67 kB
# send-email-utility-function A simple utility for sending emails using Node.js and Nodemailer. βœ‰οΈπŸš€ ## πŸ“¦ Installation ```bash npm install send-email-utility-function ``` ## πŸ› οΈ Usage ```javascript const { sendEmail } = require('send-email-utility-function'); sendEmail({ to: 'recipient@example.com', subject: 'Hello World', html: '<h1>Hello World</h1>', }).then(info => { console.log('Email sent:', info.messageId); }).catch(error => { console.error('Error sending email:', error); }); ``` ## βš™οΈ Environment Variables Make sure to set the following environment variables: - `EMAIL_USER`: Your email address πŸ“§ - `EMAIL_PASSWORD`: Your email password or app password πŸ”‘ ## πŸ”‘ How to Get a Gmail App Password If you use Gmail, you need an **App Password** instead of your regular password. Here’s how to get one: 1. **Go to your Google Account** πŸ‘‰ [Google Account](https://myaccount.google.com/) 2. **Enable 2-Step Verification** πŸ”’ Go to **Security** > **2-Step Verification** 🟒 Turn it ON (if not already enabled) 3. **Generate an App Password** πŸ”‘ In **Security**, find **App passwords** (You may need to sign in again) 4. **Create a new App Password** βž• Select **Mail** as the app πŸ’» Select your device (or choose "Other" and name it) 5. **Copy the 16-character password** πŸ“‹ Copy it and use it as your `EMAIL_PASSWORD` in your environment variables ⚠️ **Keep your app password safe!** You only need to enter it once in your `.env` file or environment settings. --- ## πŸ“„ License MIT