@akshayvg/mailer-npm-package-live
v1.0.2
Published
an npm package to send emails usin dynamic templates
Downloads
205
Readme
Email Sending NPM Package
This NPM package allows you to send emails using dynamic mail templates.
Features
- User Authentication: Clients can log in with their username and password.
- Project & Template Management: Users can set up projects, email templates, and email configurations.
- SMTP Support: Currently, only SMTP configuration is supported.
Installation
Install the package via NPM:
npm install your-package-name
Usage
Class: Mailer
The package provides a class named Mailer
, which must be instantiated using a generated API key. The API key is obtained from the application website and is only visible once.
Example:
const Mailer = require('your-package-name');
// Instantiate the Mailer class with the API key
const mailer = new Mailer('your-api-key');
Method: sendMail
After instantiating the Mailer
class, you can use the sendMail
method to send emails.
Arguments:
| Parameter | Type | Description |
|-------------------|-------------|--------------------------------------------------------------|
| templateId
| number
| The ID of the email template. |
| versionId
| number
| The version ID of the email template. |
| projectId
| number
| The ID of the project under which the email is sent. |
| providerType
| string
| The type of email provider (e.g., "SMTP"). |
| recipientEmail
| string
| The recipient's email address. |
| subject
| string
| The subject of the email. |
| templateData
| array
| An array of objects containing dynamic data fields. |
Structure of templateData
Objects:
| Property | Type | Description |
|---------------|------------|----------------------------------|
| fieldName
| string
| The name of the dynamic field. |
| fieldValue
| string
| The value for the dynamic field. |
Example:
const mailer = new Mailer('your-api-key');
const emailDetails = {
templateId: 1,
versionId: 2,
projectId: 101,
providerType: 'SMTP',
recipientEmail: '[email protected]',
subject: 'Welcome Email',
templateData: [
{ fieldName: 'userName', fieldValue: 'John Doe' },
{ fieldName: 'verificationCode', fieldValue: '123456' },
],
};
mailer.sendMail(emailDetails)
.then(response => console.log('Email sent successfully:', response))
.catch(error => console.error('Error sending email:', error));
Notes
- API Key Visibility: The API key is displayed only once upon generation.
- Supported Configuration: Only SMTP configurations are supported currently.
License
This package is licensed under the MIT License. See LICENSE
for more details.
Installation
npm install my-npm-package