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

  1. In N8N, add an Email Trigger (IMAP) node
  2. Configure your email credentials
  3. Set the trigger condition to watch for emails with specific subjects (e.g., "Quote Approval Request")
  4. 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):

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

  1. Send a test email to your configured inbox with:
  2. Subject: "Quote Approval Request"
  3. Attachments: Supplier PDF and Contractor Excel

  4. Monitor the N8N workflow execution

  5. Verify the response in the AI Quote Generator app

Notes

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