I have written a simple but full fledged inbound email processor application using mail-notifier npm which internally uses imap & mailparser. The complete source code is in my Git Repository for download or clone
[Note: Image created using Lucid chart online diagramming tool]
In this application, I have taken care of the following business functionalities
- Continuously look for all incoming email messages
- When email arrived, process it and form a modified email JSON object with the following properties
- Plain Text Body
- Message ID
- Date of the email
- Keep the configurations in a separate config file i.e. Email credentials, Mongo connection string etc.
- Save the email object into Mongo DB store
- Save the email object as .txt/.json file in “uploads” folder
- Iterate through attachments if any and store it in “uploads” folder [TODO: MongoDB GridFS]
How to run the application?
- Clone the repository or download the zip and extract into a folder
- set the SMTP configuration in “config.js” – use your email credentials
- Set MongoDB configuration – this is optional; if you don’t need it then comment out following line in “mailprocessor.js”
- Set mongo collection as “emails” – This is applicable only if point # 3 is valid.
- run “npm update” – this will download all the dependent node_modules recognized from the package.json
- run “node mailprocessor.js”
Why I created this?
- Business Motive – We have our home-grown helpdesk / ticketing system for our employees to make any kind of support tickets online however employees are comfortable in sending helpdesk tickets thru email to email@example.com; it is our process that the helpdesk / IS team should make a ticket entry for every request received thru email. This application is built to automate ticket creation from email.
- Passion – I wanted to try out in Node.JS as it is very simple due to the availability of loads of ready made NPMs but choosing the correct npm is the key
- No full-fledged sample – During the course of development I could not find complete references and samples easily i.e. mailparsing, attachments etc. I collected lot of references from stackoverflow Q&As
Scope for improvement (or TBD)
- Email filters and rules to process only those emails which matches a specific condition
- Store the attachments in the MongoDB GridFS
- MongoDB Query Analyser – MongoVUE