This service audits email files (.eml
) for grammar, tone, clarity and other rules, ensuring they meet quality standards and include at least one image attachment. It uses OpenAI LLM for email content evaluation for enabled and configured rules and provides a JSON report.
- Email Parsing: Extracts text, subject, and detects image attachments from
.eml
files. - Dynamic rules engine: Allows new rules to be integrated without changing core rules engine.
- Rule-Based Auditing: Checks grammar, tone, gretting etc using configurable LLM/ Non LLM-powered rules.
- REST API: Allows to Upload
.eml
files for auditing via a simple HTTP POST endpoint. - Docker Support: Easily deployable with Docker and Docker Compose.
.
├── src/
│ ├── app.ts # Express server and API endpoint
│ ├── eml/
│ │ ├── emailParser.ts # Parses .eml files
│ │ └── htmlToText.ts # Converts HTML to plain text
│ ├── engine/
│ │ ├── loadRules.ts # Loads enabled rules
│ │ ├── reportGenerator.ts# Generates audit reports
│ │ └── ruleEngine.ts # Runs rules on email content
│ └── rules/
│ ├── grammarRule.ts # Grammar checking rule
│ └── toneRule.ts # Tone checking rule
├── uploads/ # Uploaded .eml files (temporary)
├── email-samples/ # Sample .eml files for testing
├── package.json
├── Dockerfile
├── docker-compose.yml
├── tsconfig.json
└── .env.example # Lists required .env fields
- Node.js (v16+)
- Docker (optional, for containerized deployment)
-
Clone the repository:
git clone https://wwww.github.com/ilivestrong/ai_email_audit_service cd ai_email_audit_service
-
Install dependencies:
npm install
-
Configure environment:
- Copy
.env.example
to.env
and fill in required values.
- Copy
npm start
docker-compose up
The RESTful API server runs on port 3149 by default for local run. You can chanage it in the .env file. For Docker, port mapping can be updated in docker-compose file.
POST /email/audit
- Form field:
email
(file,.eml
format)
curl -F "email=@email-samples/polite email with image.eml" http://localhost:3149/email/audit
{
"totalScore": "0/3",
"results": [
{
"pass": false,
"explanation": "The tone is disrespectful and unprofessional, using insults and harsh language."
},
{
"pass": false,
"explanation": "The email contains grammatical errors, including improper sentence structure, missing auxiliary verbs, and punctuation issues."
},
{
"pass": false,
"explanation": "Greeting is missing or unclear at the beginning of the email."
}
],
"summary": "The email demonstrates significant weaknesses in professionalism and tone, with disrespectful language. It also contains grammatical errors and lacks a proper greeting. Improvements should focus on adopting a respectful tone, correcting grammatical issues, and including a clear greeting at the start."
}
- Rules: Enable or disable rules in
src/rules/rules.config.json
. Make sure that rule file name matches the rule key in rules.config.json. - Uploads: Uploaded files are stored in the
uploads/
directory and deleted after processing.
- Add new rules: Implement a class in
src/rules/
that extendsBaseRule
.
- For testing purpose some sample .eml files are provide in /email-samples folder
MIT
Note: This project uses OpenAI LLM for email content evaluation. Ensure your provided OpenAI API key in .env file is valid and have enough credits. It is required for this application to run successfully.