digi-sendzi/README.md

101 lines
3.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# digi-sendzi ✉️
digi-sendzi is a simple yet powerful SMTP email-sending library built in JavaScript. It provides an easy-to-use interface for sending emails, supporting plain text, HTML content, and attachments.
## Features 🌟
- **Send emails using SMTP protocol**: Reliable and secure email delivery.
- **Support for multipart emails**: Easily send both text and HTML formats.
- **Attach files to emails**: Include attachments for richer communication.
- **Basic authentication support**: Use your username and password for authentication.
- **Simple error handling**: Manage errors with ease.
## Installation 🛠️
To install digi-sendzi, you can use npm:
```bash
npm install digi-sendzi
```
## Usage 📧
Basic Example
Heres a simple example of how to use digi-sendzi to send an email:
```javascript
import { createTransport } from 'digi-sendzi';
const transporter = createTransport({
host: 'smtp.example.com',
port: 587,
auth: {
user: 'your-email@example.com',
pass: 'your-email-password'
}
});
const mailOptions = {
from: 'your-email@example.com',
to: 'recipient@example.com',
subject: 'Hello from digi-sendzi! 🌍',
text: 'This is a plain text message.',
html: '<strong>This is a bold HTML message.</strong>',
attachments: [
{
filename: 'example.txt',
content: 'Hello, this is the content of the file!',
contentType: 'text/plain'
}
]
};
transporter.sendMail(mailOptions)
.then(() => {
console.log('Email sent successfully! 🎉');
})
.catch((error) => {
console.error('Error sending email:', error.message);
});
```
## API Reference 📚
### createTransport(options)
Creates a new Transporter instance.
**options:** An object containing the following properties:
- **host** (string): The SMTP server host.
- **port** (number, optional): The port to connect to (default is 25).
- **auth** (object, optional): An object containing `user` and `pass` for authentication.
### Transporter.sendMail(mailOptions)
Sends an email with the specified options.
**mailOptions:** An object containing the following properties:
- **from** (string): Sender's email address (required).
- **to** (string): Recipient's email address (required).
- **subject** (string): Email subject (required).
- **text** (string): Plain text body of the email (required).
- **html** (string, optional): HTML body of the email.
- **attachments** (array, optional): An array of attachment objects with `filename`, `content`, and `contentType`.
## Error Handling ⚠️
digi-sendzi provides basic error handling. If any required fields are missing or an error occurs during the SMTP connection or email sending, an error will be thrown. You can catch these errors using a `.catch()` block when sending an email.
## Development 💻
To run tests, ensure you have Jest installed as a dev dependency, and run:
```bash
npm test
```
## License 📝
This project is licensed under the ISC License.
## Author ✍️
DigiMantra
## Links
* **GitHub**: [digi-sendzi Repository](https://git.digimantra.com/inder-dml/digi-sendzi.git)
* **NPM**: [digi-sendzi Package](https://www.npmjs.com/package/digi-sendzi)