A robust Node.js client for interacting with the temp-mail.org service. This client provides an object-oriented interface for creating temporary email addresses and monitoring incoming messages.
- 🚀 Easy-to-use API for temporary email management
- ⚡ Real-time message monitoring
- 🔄 Automatic retry mechanism with exponential backoff
- 🛡️ Comprehensive error handling
- 📝 Support for HTML message parsing
- 🎯 Configurable settings
- 📦 Can be used as a module or standalone script
npm install temp-mail-clientconst TempMail = require('./index.js');
async function example() {
const tempMail = new TempMail();
try {
// Initialize and create a temporary mailbox
await tempMail.initialize();
console.log('Temporary email:', tempMail.mailbox);
// Start monitoring for new messages
await tempMail.monitorMailbox(async (message) => {
console.log('New message received:', message.subject);
});
} catch (error) {
console.error('Error:', error.message);
}
}
example();const tempMail = new TempMail(config);Parameters:
config(optional): Configuration object to override default settings
{
BASE_URL: 'https://web2.temp-mail.org',
POLLING_INTERVAL: 5000, // 5 seconds
MAX_RETRIES: 3,
RETRY_DELAY: 1000, // 1 second
HEADERS: { ... } // Custom headers
}Creates a new temporary mailbox and obtains authentication token.
await tempMail.initialize();Retrieves all messages from the mailbox.
const messages = await tempMail.getMessages();Retrieves a specific message by ID.
const message = await tempMail.readMail('message-id');Starts monitoring the mailbox for new messages.
await tempMail.monitorMailbox(async (message) => {
console.log('New message:', message);
});Parameters:
callback: Function to be called for each new message
Extracts confirmation links from HTML email content.
const link = tempMail.extractConfirmationLink(message.bodyHtml);const customConfig = {
POLLING_INTERVAL: 10000, // Check every 10 seconds
MAX_RETRIES: 5, // More retries
RETRY_DELAY: 2000 // Longer delay between retries
};
const tempMail = new TempMail(customConfig);const tempMail = new TempMail();
await tempMail.initialize();
await tempMail.monitorMailbox(async (message) => {
// Process message content
console.log('From:', message.from);
console.log('Subject:', message.subject);
// Extract confirmation link if present
const link = tempMail.extractConfirmationLink(message.bodyHtml);
if (link) {
console.log('Found confirmation link:', link);
// Process the link...
}
});try {
const tempMail = new TempMail();
await tempMail.initialize();
} catch (error) {
if (error.name === 'APIError') {
console.error('API Error:', error.message, 'Status:', error.statusCode);
} else {
console.error('General Error:', error.message);
}
}Thrown when the API returns an error response.
- Properties:
message: Error descriptionstatusCode: HTTP status codename: Always 'APIError'
.
├── index.js # Main implementation
└── README.md # Documentation
npm test- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- temp-mail.org for providing the temporary email service
- Cheerio for HTML parsing capabilities
For support, please open an issue in the GitHub repository.