Introduction

Email-based support is still the preferred channel for many customers. In this tutorial, we’ll build a complete support ticket system that automatically creates tickets from incoming emails.

Architecture Overview

Our system will:

  1. Receive customer emails via webhook
  2. Parse the email content and metadata
  3. Create or update tickets in our database
  4. Send automated acknowledgment replies

Setting Up the Webhook

First, configure MailWebhook to forward emails from your support address:

{
  "mailbox": "support@company.com",
  "webhook_url": "https://api.company.com/webhooks/support",
  "filters": {
    "exclude_from": ["noreply@*", "mailer-daemon@*"]
  }
}

Creating Tickets

When a webhook arrives, we parse the email and create a ticket:

async function handleSupportEmail(payload) {
  const { from, subject, body, messageId } = payload
  
  // Check if this is a reply to an existing ticket
  const existingTicket = await findTicketByThread(messageId)
  
  if (existingTicket) {
    await addReplyToTicket(existingTicket.id, {
      from: from.email,
      content: body.text
    })
  } else {
    await createNewTicket({
      customer_email: from.email,
      customer_name: from.name,
      subject,
      initial_message: body.text,
      thread_id: messageId
    })
  }
}

Routing and Prioritization

You can automatically route tickets based on email content:

function determineTicketPriority(subject, body) {
  const urgentKeywords = ['urgent', 'asap', 'emergency', 'critical']
  const content = (subject + ' ' + body).toLowerCase()
  
  if (urgentKeywords.some(keyword => content.includes(keyword))) {
    return 'high'
  }
  return 'normal'
}

Conclusion

With MailWebhook handling the email infrastructure, you can focus on building great support experiences for your customers.