Process Incoming Emails and Trigger a Workflow
Process Incoming Emails and Trigger a Workflow
Section titled “Process Incoming Emails and Trigger a Workflow”In this tutorial, you’ll configure Lowgile to listen for incoming emails, capture their content (including attachments), and trigger a workflow.
This pattern is useful for building email-driven applications such as order intake, support ticketing, or document processing.
What you’ll build
Section titled “What you’ll build”By the end of this tutorial, you will:
- Configure a mail server connection
- Listen for incoming emails
- Filter relevant messages
- Extract email data and attachments
- Store the data in your application
- Trigger a workflow process
Prerequisites
Section titled “Prerequisites”- Access to a mail server (IMAP/SMTP)
- Credentials for the mailbox
- A module to store incoming email data
- A workflow process to trigger
Step 1: Configure the mail server
Section titled “Step 1: Configure the mail server”Create a configuration item for your email connection.
Go to Settings → Configuration and create a new item (e.g. emailConfig) of type Mail Server Connection.
Provide:
- Host (mail server address)
- Username and password
- IMAP and SMTP ports (optional)
- From address
Tip
Use mock recipients during development to prevent sending real emails.
Step 2: Create an incoming email trigger
Section titled “Step 2: Create an incoming email trigger”Add a new trigger to your module:
- Trigger type: Incoming Email
- Mailbox:
emailConfig - Mailbox folder:
INBOX
Recommended options:
- Ignore read emails
- Mark emails as read after processing
Step 3: Filter relevant emails
Section titled “Step 3: Filter relevant emails”Add a filter to process only specific emails.
Example:
return mail.subject.startsWith("Order:");This ensures only matching emails trigger your logic.
Step 4: Extract email data
Section titled “Step 4: Extract email data”Inside the trigger handler, extract the email content:
const attachments = mail.attachments.map(a => ({ fileName: a.fileName, data: a.data}));
const emailData = { from: mail.from, subject: mail.subject, body: mail.body, attachments};This gives you structured access to:
- Sender
- Subject
- Message body
- Attachments
Step 5: Store the email in your application
Section titled “Step 5: Store the email in your application”Save the extracted data to your data model:
const emailRecord = await IncomingEmail.create(emailData);This allows you to:
- Persist the email
- Reference it later in workflows
Step 6: Trigger a workflow process
Section titled “Step 6: Trigger a workflow process”Start a process using the stored email:
await this.process.start("processIncomingEmail", { emailId: emailRecord.id});This hands off control to your workflow engine.
Step 7: Handle the email in the workflow
Section titled “Step 7: Handle the email in the workflow”In your process:
- Load the email using
emailId - Process attachments (e.g. with AI)
- Route tasks to users or automation steps
Result
Section titled “Result”You now have an email-driven workflow:
- Emails are automatically detected
- Relevant messages are processed
- Data is stored and structured
- A workflow is triggered for further handling
What’s happening
Section titled “What’s happening”Lowgile listens to the mailbox using the configured connection.
When a new email arrives:
- The trigger evaluates the filter
- Matching emails are processed
- Data is extracted and stored
- A workflow process is started
This enables fully automated, event-driven applications.
Next steps
Section titled “Next steps”- Parse attachments using AI
- Send automated replies
- Route emails to different workflows
- Build approval or processing pipelines
Related guides
Section titled “Related guides”- Email Triggers
- Sending Emails
- AI Structured Extraction
- Workflow Fundamentals