1.0.1 • Published 1 year ago

@arunvaradharajalu/common.mail-client v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

@arunvaradharajalu/common.mail-client

npm version GitHub issues GitHub license

This package provides a mail client using nodemailer under the hood for sending emails.

Installation

To install the package, use npm or yarn:

npm install @arunvaradharajalu/common.mail-client

Usage

Here is an example of how to use the mail client:

import { MailClientImpl } from '@arunvaradharajalu/common.mail-client';

// Create an instance of the MailClientImpl
const mailClient = new MailClientImpl();

// Set SMTP configuration
mailClient.host = 'smtp.example.com';
mailClient.port = 587;
mailClient.user = 'your-email@example.com';
mailClient.password = 'your-email-password';

// Initialize the mail client
mailClient.init();

// Define the email message
const message = {
    from: 'your-email@example.com',
    to: 'recipient@example.com',
    subject: 'Test Email',
    text: 'This is a test email',
    html: '<p>This is a test email</p>',
};

// Send the email
mailClient.sendMail(message, message.html, message.subject, message.text)
    .then(() => {
        console.log('Email sent successfully!');
    })
    .catch(error => {
        console.error('Error sending email:', error);
    });

API

MailClientImpl

Properties

  • host: string | null - Sets the SMTP host.
  • port: number | null - Sets the SMTP port.
  • user: string | null - Sets the SMTP user.
  • password: string | null - Sets the SMTP password.

Methods

  • init(): void - Initializes the mail client with the provided SMTP configuration.
  • sendMail(message: MailMessage, html: string, subject: string, text: string): Promise<void> - Sends an email with the provided message, HTML content, subject, and text content.
  • getTemplateString(templateFolderPath: string, type: TemplateTypes): Promise<string> - Retrieves the email template string from the specified folder path and type.
  • compile(template: any, data: { [key: string]: any }): string - Compiles the email template with the provided data.

Running Tests

To run the tests, use:

npm test

The test results will be generated in an HTML report with the title "Mail Client Test Report".

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue for bug fixes, improvements, or new features.

Author

Arun Varadharajalu

License

This project is licensed under the ISC License.