.gitea/workflows | ||
.vscode | ||
assets | ||
test | ||
ts | ||
.gitignore | ||
dependencies.yml | ||
license | ||
npmextra.json | ||
package.json | ||
pnpm-lock.yaml | ||
readme.hints.md | ||
readme.md | ||
tsconfig.json |
@push.rocks/smartmail
a unified format for representing and dealing with mails
Install
To install @push.rocks/smartmail
, you'll need Node.js installed on your system. With Node.js installed, run the following command in your terminal:
npm install @push.rocks/smartmail --save
This will add @push.rocks/smartmail
to your project's dependencies.
Usage
@push.rocks/smartmail
provides a unified format for representing and dealing with emails in a Node.js environment. Below, you will find several examples showcasing how to use its main features, including email address validation and creation of mail objects with attachments.
Importing the Module
First, ensure you're using ESM (ECMAScript Modules) syntax in your TypeScript project. Then, import the necessary classes:
import {
Smartmail,
EmailAddressValidator
} from '@push.rocks/smartmail';
Validate Email Addresses
You can validate email addresses to check whether they are disposable, belong to a free email provider, or verify their validity in terms of having an MX record.
// Instantiate the EmailAddressValidator
const emailValidator = new EmailAddressValidator();
// Validate an email address
const validateEmail = async (email: string) => {
const validationResult = await emailValidator.validate(email);
console.log(validationResult);
};
// Example usage
validateEmail('example@gmail.com').then(() => {
console.log('Email validation completed.');
});
Creating and Using Smartmail Objects
Smartmail
class allows you to represent an email in a structured way, including attachments, subject, body, and more. Here's how to use it:
import { Smartmail } from '@push.rocks/smartmail';
import { Smartfile } from '@push.rocks/smartfile';
// Create a new Smartmail object
const myMail = new Smartmail({
from: 'no-reply@yourdomain.com',
subject: 'Welcome to Our Service',
body: 'Hello {{name}}, welcome to our service!'
});
// Use Smartfile to prepare an attachment (optional)
const attachment = new Smartfile.fromLocalPath('path/to/your/attachment.pdf');
myMail.addAttachment(attachment);
// Accessing and modifying the mail object's properties
console.log(myMail.getSubject({ name: 'John Doe' }));
console.log(myMail.getBody({ name: 'John Doe' }));
// The `getCreationObject` method can be used to retrieve the original creation object
console.log(myMail.getCreationObject());
Email Address Validation Details
The EmailAddressValidator
class fetches domain information either from a local JSON file or an online source to categorize email domains as disposable, free, or valid based on MX records. Here's a deeper look into validating email addresses and interpreting the results:
// Instantiate the validator
const validator = new EmailAddressValidator();
// Validate an email
validator.validate('someone@disposablemail.com').then(result => {
if (result.valid && !result.disposable) {
console.log('Email is valid and not disposable.');
} else {
console.log('Email is either invalid or disposable.');
}
if (result.freemail) {
console.log('Email belongs to a free mail provider.');
}
});
Handling Attachments
As shown in the example, attachments can be added to a Smartmail
object. Smartfile
(from @push.rocks/smartfile
) is utilized to handle file operations, allowing you to attach files easily to your email object. Ensure that attachments are in the appropriate format and accessible before adding them to the Smartmail
object.
Conclusion
These examples cover the basics of using @push.rocks/smartmail
for handling emails within your Node.js applications. By leveraging the Smartmail
and EmailAddressValidator
classes, you can efficiently represent, validate, and manage email data, enhancing the robustness and functionality of your email-related features.
License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the license file within this repository.
Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.