gmail-node-mailer
Advanced tools
Comparing version 1.6.59 to 1.6.601
@@ -1,1 +0,1 @@ | ||
export { GmailMailer } from './gmailer'; | ||
export { GmailMailer } from './GmailMailer'; |
@@ -5,3 +5,3 @@ "use strict"; | ||
// ./src/index.ts | ||
var gmailer_1 = require("./gmailer"); | ||
Object.defineProperty(exports, "GmailMailer", { enumerable: true, get: function () { return gmailer_1.GmailMailer; } }); | ||
var GmailMailer_1 = require("./GmailMailer"); | ||
Object.defineProperty(exports, "GmailMailer", { enumerable: true, get: function () { return GmailMailer_1.GmailMailer; } }); |
@@ -0,1 +1,12 @@ | ||
/** | ||
* Checks if the provided string is a valid email address. | ||
* | ||
* This function uses a regular expression to validate the email format. It checks for a general | ||
* pattern that includes characters before the "@" symbol, followed by characters after it, | ||
* and finally a domain suffix. This is a basic validation and might not cover all edge cases | ||
* of email address validation according to the RFC specifications. | ||
* | ||
* @param {string} email The email address to validate. | ||
* @returns {boolean} True if the email address is valid, false otherwise. | ||
*/ | ||
export declare function isValidEmail(email: string): boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isValidEmail = void 0; | ||
// Function to validate email pattern | ||
/** | ||
* Checks if the provided string is a valid email address. | ||
* | ||
* This function uses a regular expression to validate the email format. It checks for a general | ||
* pattern that includes characters before the "@" symbol, followed by characters after it, | ||
* and finally a domain suffix. This is a basic validation and might not cover all edge cases | ||
* of email address validation according to the RFC specifications. | ||
* | ||
* @param {string} email The email address to validate. | ||
* @returns {boolean} True if the email address is valid, false otherwise. | ||
*/ | ||
function isValidEmail(email) { | ||
const regexPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||
return regexPattern.test(email); | ||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||
return emailRegex.test(email); | ||
} | ||
exports.isValidEmail = isValidEmail; |
{ | ||
"name": "gmail-node-mailer", | ||
"version": "1.6.59", | ||
"version": "1.6.601", | ||
"description": "", | ||
@@ -8,3 +8,3 @@ "main": "dist/index.js", | ||
"build": "tsc", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "jest" | ||
}, | ||
@@ -18,5 +18,9 @@ "keywords": [], | ||
"devDependencies": { | ||
"@types/jest": "^29.5.12", | ||
"@types/mocha": "^10.0.6", | ||
"dotenv": "^16.4.5", | ||
"jest": "^29.7.0", | ||
"ts-jest": "^29.1.2", | ||
"typescript": "^5.4.2" | ||
} | ||
} |
@@ -1,47 +0,37 @@ | ||
# Gmail Node Mailer Package | ||
# Gmail Node Mailer | ||
This Node.js package simplifies sending emails using the Gmail API. It wraps the complexity of Google's authentication and email sending process into a few easy-to-use functions. | ||
The \`gmail-node-mailer\` package provides a streamlined way to send emails using the Gmail API within Node.js applications. This package simplifies the process of setting up the Gmail API client, validating email addresses, and sending emails. It also offers flexibility by allowing users to configure the Gmail service account and sender email dynamically. | ||
## Features | ||
- Easy Gmail API authentication using service accounts. | ||
- Send emails with simple function calls. | ||
- Includes TypeScript definitions for better development experience. | ||
- Initialize the Gmail API client with service account credentials. | ||
- Validate sender and recipient email addresses. | ||
- Send emails with customizable sender, recipient, subject, and message content. | ||
- Configure service account and sender email through utility functions. | ||
## Installation | ||
## Getting Started | ||
\`\`\`bash | ||
npm install gmail-node-mailer | ||
\`\`\` | ||
### Installation | ||
Or if you prefer using Yarn: | ||
To install the package, run the following command in your Node.js project directory: | ||
\`\`\`bash | ||
yarn add gmail-node-mailer | ||
npm install gmail-node-mailer | ||
\`\`\` | ||
## Quick Start | ||
### Usage | ||
First, ensure you have a service account set up in your Google Cloud Project and have downloaded the service account JSON file. Also, make sure the Gmail API is enabled. | ||
1. **Initialize the Gmail API Client** | ||
### Setting Up Environment Variables | ||
Before sending emails, you must initialize the Gmail API client with your service account credentials. | ||
Create a \`.env\` file in your project's root directory and add the following variables: | ||
\`\`\`typescript | ||
import { GmailMailer } from 'gmail-node-mailer'; | ||
\`\`\`plaintext | ||
GMAIL_USER=your_email@example.com | ||
\`\`\` | ||
const mailer = new GmailMailer(); | ||
Replace \`your_email@example.com\` with the email address of the Google account you wish to send emails from. Ensure this account is associated with your Google Cloud Project and has the Gmail API enabled. | ||
### Using the Package | ||
1. **Initialize the Email Client** | ||
Import and call \`initializeClient\` at the start of your application. This function initializes the Gmail API client using credentials from your service account JSON file and the sender email from your environment variables. | ||
\`\`\`javascript | ||
import { initializeClient } from 'gmail-node-mailer'; | ||
const emailClient = await initializeClient(); | ||
// Initialize with your service account credentials | ||
await mailer.initializeClient({ | ||
gmailServiceAccountPath: '/path/to/service-account.json', | ||
}); | ||
\`\`\` | ||
@@ -51,40 +41,31 @@ | ||
Once the client is initialized, you can send emails using the \`sendEmail\` function. | ||
After initializing the client, you can send emails by providing the sender, recipient, subject, and message. | ||
\`\`\`javascript | ||
import { sendEmail } from 'gmail-node-mailer'; | ||
\`\`\`typescript | ||
const emailParams = { | ||
senderEmail: 'your-email@gmail.com', | ||
recipientEmail: 'recipient-email@gmail.com', | ||
subject: 'Hello from Gmail Node Mailer', | ||
message: 'This is a test email sent using the Gmail Node Mailer package.', | ||
}; | ||
const emailResponse = await sendEmail({ | ||
senderEmail: 'your_email@example.com', | ||
recipientEmail: 'recipient@example.com', | ||
subject: 'Hello World', | ||
message: 'This is a test email sent from gmail-node-mailer.' | ||
}); | ||
console.log(emailResponse); | ||
const response = await mailer.sendEmailWrapper(emailParams); | ||
console.log(response.message); | ||
\`\`\` | ||
## API Reference | ||
## Configuration | ||
### \`initializeClient(options?)\` | ||
- **Service Account**: Set the path to your service account JSON file or directly provide the service account object. | ||
- **Sender Email**: Configure the default sender email address. | ||
Initializes and returns the Gmail API client. | ||
## Utilities | ||
- **options** (optional): An object containing \`serviceAccount\` and \`senderEmail\`. If not provided, the package will use the service account JSON file located at \`./private/service_account.json\` and the \`GMAIL_USER\` environment variable. | ||
This package includes utilities for validating email addresses, parsing service account files, and managing configuration settings. | ||
### \`sendEmail({ senderEmail, recipientEmail, subject, message })\` | ||
Sends an email using the initialized Gmail API client. | ||
- **senderEmail**: The email address of the sender. | ||
- **recipientEmail**: The email address of the recipient. | ||
- **subject**: The subject of the email. | ||
- **message**: The plain text message body of the email. | ||
## Contributing | ||
Contributions are welcome! Please open an issue or submit a pull request for any improvements you wish to make. | ||
Contributions, issues, and feature requests are welcome! Feel free to check [issues page](#). | ||
## License | ||
This project is licensed under the MIT License - see the LICENSE file for details. | ||
Distributed under the MIT License. See \`LICENSE\` for more information. |
// ./src/index.ts | ||
export { GmailMailer } from './gmailer'; | ||
export { GmailMailer } from './GmailMailer'; |
@@ -1,5 +0,15 @@ | ||
// Function to validate email pattern | ||
/** | ||
* Checks if the provided string is a valid email address. | ||
* | ||
* This function uses a regular expression to validate the email format. It checks for a general | ||
* pattern that includes characters before the "@" symbol, followed by characters after it, | ||
* and finally a domain suffix. This is a basic validation and might not cover all edge cases | ||
* of email address validation according to the RFC specifications. | ||
* | ||
* @param {string} email The email address to validate. | ||
* @returns {boolean} True if the email address is valid, false otherwise. | ||
*/ | ||
export function isValidEmail(email: string): boolean { | ||
const regexPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||
return regexPattern.test(email); | ||
} | ||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||
return emailRegex.test(email); | ||
} |
@@ -14,4 +14,4 @@ { | ||
"src/**/*" | ||
], | ||
, "src/__tests__" ], | ||
"exclude": ["node_modules"] | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
196987
35
5105
1
6
71
8
1