Skip to content

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.


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

  • Access to a mail server (IMAP/SMTP)
  • Credentials for the mailbox
  • A module to store incoming email data
  • A workflow process to trigger

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.


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

Add a filter to process only specific emails.

Example:

return mail.subject.startsWith("Order:");

This ensures only matching emails trigger your logic.


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

Start a process using the stored email:

await this.process.start("processIncomingEmail", {
emailId: emailRecord.id
});

This hands off control to your workflow engine.


In your process:

  • Load the email using emailId
  • Process attachments (e.g. with AI)
  • Route tasks to users or automation steps

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

Lowgile listens to the mailbox using the configured connection.

When a new email arrives:

  1. The trigger evaluates the filter
  2. Matching emails are processed
  3. Data is extracted and stored
  4. A workflow process is started

This enables fully automated, event-driven applications.


  • Parse attachments using AI
  • Send automated replies
  • Route emails to different workflows
  • Build approval or processing pipelines

  • Email Triggers
  • Sending Emails
  • AI Structured Extraction
  • Workflow Fundamentals