Node.js email handling examples
This example demonstrates a complete round-trip email workflow in Node.js, showing how to send and receive messages with attachments. It sends an image file via SMTP using EmailJS, then connects to an IMAP server with node-imap to search for unread messages from the sender, parses them with MailParser, and writes any attachments back to disk. The scripts rely on a shared JSON config file for account credentials and server settings, and both the send and receive operations are driven by callback-based asynchronous flows.
AI-generated descriptionSome examples of sending and receiving emails with Node.js.
This uses the following libraries:
- emailjs for sending email
- node-imap for receiving email
- mailparser for parsing received emails
Running
Copy config.json.example to config.json and enter your email account details.
Run coffee send.coffee to send yourself an email with an attachment.
Run coffee read.coffee to receive the sent email and write the attachment back to disk with a new name.