N8N Email Trigger Integration
This document describes how to configure N8N to automatically process quote approval requests from email and push them to the AI Quote Generator.
Workflow Overview
Email Trigger → Extract Attachments → Send to AI Quote Generator → (Optional) Push to QBO
Step 1: Configure Email Trigger
- In N8N, add an Email Trigger (IMAP) node
- Configure your email credentials
- Set the trigger condition to watch for emails with specific subjects (e.g., "Quote Approval Request")
- Enable "Download Attachments"
Step 2: Process Attachments
Add a Code node to identify and prepare the PDF and Excel files:
// Extract attachments from email
const attachments = $input.item.json.attachments || [];
let pdfAttachment = null;
let excelAttachment = null;
for (const att of attachments) {
const filename = att.filename.toLowerCase();
if (filename.endsWith('.pdf')) {
pdfAttachment = att;
} else if (filename.endsWith('.xlsx') || filename.endsWith('.xls')) {
excelAttachment = att;
}
}
if (!pdfAttachment) {
throw new Error('No PDF attachment found in email');
}
return {
json: {
pdfData: pdfAttachment.data,
pdfFilename: pdfAttachment.filename,
excelData: excelAttachment?.data,
excelFilename: excelAttachment?.filename,
emailFrom: $input.item.json.from,
emailSubject: $input.item.json.subject,
hasExcel: !!excelAttachment
}
};
Step 3: Send to AI Quote Generator
Add an HTTP Request node:
Method: POST
URL: http://localhost:3000/api/n8n-intake
Authentication: None (internal request)
Body Content Type: Multipart-Form Data
Body Parameters:
- pdf (File from Binary Data): {{ $json.pdfData }}
- excel (File from Binary Data): {{ $json.excelData }} (optional)
Send Binary Data: Yes
Step 4: Process Response
The API will return JSON with the analyzed quote:
{
"supplier": {
"vendorName": "Sencore Inc",
"quoteNumber": "Q-2024-001",
"items": [...]
},
"contractor": {
"customerName": "ABC Corp",
"items": [...],
"shippingQuoted": 150
},
"audit": {
"discrepancies": [...],
"summary": "..."
},
"isAudit": true,
"timestamp": "2026-01-31T22:45:00.000Z",
"source": "n8n-intake"
}
Step 5: Conditional QBO Push (Optional)
Add an IF node to check if the quote is valid:
Condition: {{ $json.audit.discrepancies.length === 0 }}
If TRUE (Quote Validated):
Add an HTTP Request node to create the QBO estimate:
Method: POST
URL: http://localhost:3000/api/create-qbo-estimate
Body Content Type: JSON
Body:
{
"documentId": "{{ $json.supplier.quoteNumber }}",
"customer": "{{ $json.contractor.customerName }}",
"customerLocation": {
"province": "ON",
"postalCode": "M5V 3A8"
},
"lineItems": "{{ $json.contractor.items.map(item => ({ description: item.description, sku: item.sku, amount: item.price })) }}"
}
If FALSE (Discrepancies Found):
- Send a notification email to the user with the discrepancies
- Consider adding the quote to a review queue
Step 6: Send Confirmation Email
Add a Send Email node to notify the sales team:
Subject: Quote {{ $json.supplier.quoteNumber }} - {{ $json.audit.discrepancies.length === 0 ? 'Approved' : 'Requires Review' }}
Body:
Quote Analysis Complete
Supplier: {{ $json.supplier.vendorName }}
Quote #: {{ $json.supplier.quoteNumber }}
Customer: {{ $json.contractor.customerName }}
Status: {{ $json.audit.discrepancies.length === 0 ? '✅ VALIDATED' : '⚠️ DISCREPANCIES FOUND' }}
{{ $json.audit.summary }}
View full details in the AI Quote Generator dashboard.
Testing
- Send a test email to your configured inbox with:
- Subject: "Quote Approval Request"
-
Attachments: Supplier PDF and Contractor Excel
-
Monitor the N8N workflow execution
-
Verify the response in the AI Quote Generator app
Notes
- The Excel-to-image Python service must be running on port 5000
- The AI Quote Generator must be running on port 3000
- Ensure network firewall allows localhost connections
- For production, use proper authentication and HTTPS
Troubleshooting
"Excel conversion failed":
- Check if python excel_api_simple.py is running in n8n-v2/
"PDF text extraction failed": - Verify the PDF is not encrypted or image-only
"No attachments found": - Ensure N8N email trigger has "Download Attachments" enabled