My App
Email Ingestion

Configuration

Configure email addresses, routing rules, and processing options

Configuration

This guide covers advanced configuration options for email ingestion.

Email Address Configuration

Email Prefixes

Each organization can configure multiple email prefixes, each with its own settings:

interface EmailIngestionConfig {
  // Email prefix (e.g., 'invoices', 'bills', 'expenses')
  emailPrefix: string;

  // Default document type when classification fails
  defaultDocumentType: DocumentType;

  // Use AI to classify incoming documents
  autoClassify: boolean;

  // NetSuite connection for record creation
  netsuiteConnectionId?: string;

  // Enable/disable this email address
  isActive: boolean;
}

Creating Email Prefixes

Via the Dashboard:

  1. Navigate to Settings > Integrations > Email Ingestion
  2. Click Add Email Address
  3. Enter the prefix (letters, numbers, hyphens only)
  4. Configure processing options
  5. Save and test

Via the API:

const response = await fetch('/api/email-ingestion/config', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer sk_...',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    emailPrefix: 'invoices',
    defaultDocumentType: 'vendor_bill',
    autoClassify: true,
    netsuiteConnectionId: 'conn_abc123'
  })
});

Reserved Prefixes

Some prefixes are reserved and cannot be used:

  • admin, support, help, info
  • noreply, no-reply, donotreply
  • postmaster, abuse, webmaster

Classification Settings

Auto-Classification

When autoClassify is enabled, the AI classifier analyzes:

  1. Email metadata: Subject, sender, headers
  2. Document content: Text, layout, visual elements
  3. Attachment filename: Pattern matching
// Classification result
interface ClassificationResult {
  documentType: DocumentType;
  confidence: number;      // 0.0 - 1.0
  reasoning: string;       // AI explanation
  detectedVendor?: string; // Extracted vendor name
  detectedCustomer?: string;
  keyIndicators: string[]; // What triggered classification
}

Confidence Thresholds

Configure how the system handles different confidence levels:

ConfidenceAction
>= 0.9Auto-process immediately
0.7 - 0.9Process with review flag
< 0.7Send to human review queue
// Custom thresholds (per email prefix)
{
  emailPrefix: 'invoices',
  confidenceThresholds: {
    autoProcess: 0.9,
    reviewFlag: 0.7,
    humanReview: 0.5
  }
}

Classification Override

Force a specific document type based on email patterns:

{
  emailPrefix: 'expenses',
  classificationOverrides: [
    {
      // If sender matches, force document type
      condition: { senderDomain: 'uber.com' },
      documentType: 'receipt'
    },
    {
      // If subject contains keyword
      condition: { subjectContains: 'expense report' },
      documentType: 'expense_report'
    }
  ]
}

Processing Options

Attachment Handling

interface AttachmentSettings {
  // Maximum attachment size in bytes (default: 25MB)
  maxSizeBytes: number;

  // Allowed MIME types
  allowedMimeTypes: string[];

  // Process inline images from email body
  processInlineImages: boolean;

  // Combine multiple attachments into one job
  combineAttachments: boolean;
}

Default allowed MIME types:

  • application/pdf
  • image/png
  • image/jpeg
  • image/webp
  • image/tiff

Processing Priority

Set priority for different email sources:

{
  emailPrefix: 'urgent',
  processingPriority: 'high',  // 'low' | 'normal' | 'high' | 'critical'
  maxProcessingTimeMs: 30000
}

Notification Settings

Sender Notifications

Configure emails sent to document senders:

interface NotificationSettings {
  // Send confirmation when document is received
  sendReceiptConfirmation: boolean;

  // Send notification when processing is complete
  sendProcessingComplete: boolean;

  // Send notification on errors
  sendErrorNotification: boolean;

  // Custom "from" address for notifications
  notificationFromAddress?: string;
}

Internal Notifications

Configure notifications to your team:

{
  emailPrefix: 'invoices',
  internalNotifications: {
    // Email addresses for notifications
    recipients: ['accounting@company.com'],

    // Events to notify on
    events: [
      'document_received',
      'human_review_needed',
      'netsuite_sync_failed'
    ],

    // Daily digest instead of real-time
    digestMode: false
  }
}

Routing Rules

Sender-Based Routing

Route documents based on sender:

{
  emailPrefix: 'invoices',
  routingRules: [
    {
      condition: {
        type: 'sender_domain',
        value: 'supplier1.com'
      },
      action: {
        assignTo: 'accounts-payable',
        priority: 'high',
        netsuiteSubsidiary: 'US Operations'
      }
    }
  ]
}

Subject-Based Routing

Route based on email subject:

{
  routingRules: [
    {
      condition: {
        type: 'subject_matches',
        pattern: '^PO-\\d+',  // Regex pattern
      },
      action: {
        documentType: 'purchase_order',
        autoApprove: false
      }
    }
  ]
}

Amount-Based Routing

Route high-value documents differently:

{
  routingRules: [
    {
      condition: {
        type: 'extracted_amount',
        operator: 'greater_than',
        value: 10000
      },
      action: {
        requiresApproval: true,
        approvers: ['cfo@company.com'],
        priority: 'critical'
      }
    }
  ]
}

Duplicate Detection

Configure how duplicates are handled:

interface DuplicateSettings {
  // Enable duplicate detection
  enabled: boolean;

  // Fields to check for duplicates
  matchFields: string[];  // e.g., ['invoiceNumber', 'vendorName', 'total']

  // Time window for duplicate check (hours)
  lookbackHours: number;

  // Action on duplicate
  action: 'reject' | 'flag' | 'process';
}

Default duplicate fields:

  • Invoice Number + Vendor
  • Document Hash (for identical files)

Integration Settings

Webhook Configuration

Receive real-time updates via webhooks:

{
  emailPrefix: 'invoices',
  webhooks: {
    url: 'https://your-app.com/webhooks/adteco',
    secret: 'whsec_...',
    events: [
      'email.received',
      'document.classified',
      'extraction.completed',
      'netsuite.synced',
      'netsuite.failed'
    ]
  }
}

API Access

Enable API access for programmatic configuration:

// List all configurations
GET /api/email-ingestion/config

// Get specific configuration
GET /api/email-ingestion/config/{prefix}

// Update configuration
PATCH /api/email-ingestion/config/{prefix}

// Delete configuration
DELETE /api/email-ingestion/config/{prefix}

Environment Variables

Required environment variables for self-hosted deployments:

# AWS SES Configuration
AWS_SES_REGION=us-west-2
INBOUND_EMAIL_BUCKET=your-bucket-name

# Email Domain
EMAIL_DOMAIN=adteco.io

# Processing
MAX_ATTACHMENT_SIZE_MB=25
PROCESSING_TIMEOUT_MS=120000

Troubleshooting Configuration

Test Your Configuration

Use the test endpoint to verify settings:

curl -X POST /api/email-ingestion/test \
  -H "Authorization: Bearer sk_..." \
  -H "Content-Type: application/json" \
  -d '{
    "emailPrefix": "invoices",
    "testDocument": "base64...",
    "simulateOnly": true
  }'

Common Issues

Email not being received:

  • Verify MX records are configured correctly
  • Check the email prefix is active
  • Ensure sender is not in spam/blocklist

Classification always returning low confidence:

  • Improve document quality (higher resolution scans)
  • Add classification overrides for known senders
  • Adjust confidence thresholds

NetSuite sync failing:

  • Verify connection credentials
  • Check entity existence (vendor must exist)
  • Review required field mappings