Skip to main content

Email Configuration

The ticket system uses email for ticket creation (inbound), notifications (outbound), and client communication. Email is fetched and sent via Microsoft 365 OAuth (Graph API).


Email Accounts Overview

Navigate to Admin → Emails to manage email accounts.

AccountPurpose
System EmailDefault sender for system notifications
Department EmailsPer-department inbound/outbound addresses
Alert EmailSender for internal staff alerts
Auto-Response EmailSender for client auto-replies

Adding a New Email Account

Step 1: Create Email in Admin Panel

  1. Navigate to Admin → Emails → Add New Email
  2. Fill in:
FieldDescription
Email AddressThe email address (e.g., [email protected])
Email NameDisplay name for outbound emails
DepartmentRoute inbound emails to this department
PriorityDefault priority for tickets from this email
Auto-ResponseEnable/disable auto-reply

Step 2: Configure OAuth (Microsoft 365)

  1. Go to the email account's Remote Mailbox tab
  2. Select Microsoft 365 OAuth as the fetch method
  3. Enter Azure AD credentials:
    • Tenant ID
    • Client ID
    • Client Secret
  4. Click Authorize — complete Microsoft login
  5. Test fetch: verify "Last Fetch" timestamp updates

Step 3: Configure Outgoing (SMTP via Graph)

  1. Go to the Sending Email tab
  2. Select Microsoft Graph API as the send method
  3. OAuth tokens are shared with the fetch configuration
  4. Send a test email to verify

See Microsoft 365 Integration for Azure AD setup details.


Email Templates

System Templates

Navigate to Admin → Emails → Templates to customize:

TemplateTrigger
New Ticket Auto-ResponseClient creates a ticket
New Ticket AlertStaff notification of new ticket
New Message AlertStaff notification of client reply
Response/Reply TemplateStaff reply wrapper
Ticket Assignment AlertStaff assigned to ticket
Ticket Transfer AlertTicket transferred
Overdue AlertSLA breached
Ticket ClosedConfirmation to client

Template Variables

Templates use %{variable} syntax:

VariableValue
%{ticket.number}Ticket display number
%{ticket.subject}Ticket subject line
%{ticket.status}Current status name
%{ticket.priority}Priority level
%{ticket.dept}Department name
%{ticket.staff}Assigned staff name
%{ticket.createDate}Creation date
%{ticket.lastMessage}Most recent message
%{recipient.name}Email recipient name
%{url}Ticket URL (uses ?number= format)

URL Format in Templates

Always use ticket number in URLs:

<a href="tickets.php?number=%{ticket.number}">View Ticket #%{ticket.number}</a>

Email Threading

How Replies Are Matched to Tickets

When an inbound email arrives, the system matches it to an existing ticket:

  1. Message-ID / In-Reply-To — Checks if the email references a previous message from this ticket
  2. References header — Checks the full reference chain
  3. Subject line pattern — Extracts [#XXXXXX] ticket number from subject

If no match is found, a new ticket is created.

Thread Subject Format

Outbound emails include the ticket number in the subject:

[#108749] Re: Checkout page error

This ensures client replies are threaded correctly even if email headers are stripped.


Auto-Reply Detection

The system detects and discards auto-replies to prevent loops:

HeaderPattern
X-Auto-Responded-SuppressAny value present
Auto-Submittedauto-replied, auto-generated
X-AutoreplyAny value present
Precedencebulk, junk, list
Subject patterns"Out of Office", "Automatic reply", "Undeliverable"

Inline Images

HTML emails with inline images (CID references) are handled:

  1. MIME multipart email parsed
  2. CID-referenced attachments extracted
  3. Images saved to osTicket file storage
  4. HTML src="cid:..." references replaced with attachment URLs
  5. Images display correctly in ticket thread view

Email Fetching Schedule

SettingValue
Fetch MethodMicrosoft 365 OAuth (Graph API)
FrequencyEvery cron run (1 minute intervals)
Batch SizeUp to 20 emails per fetch
Read StatusMarks fetched emails as read
FolderInbox (configurable)

Verifying Email Fetch

  1. Check Admin → Emails → (account) for "Last Fetch" timestamp
  2. Query the system log:
SELECT * FROM ost_syslog
WHERE title LIKE '%mail%'
ORDER BY created DESC
LIMIT 10;

Troubleshooting

IssueSolution
Emails not being fetchedCheck OAuth token is valid; re-authorize if needed
Auto-replies creating ticketsCheck auto-reply detection rules; add custom filter
Images not displayingVerify inline image processing is working; check file permissions
Duplicate tickets from same emailCheck email threading; verify Message-ID headers preserved
"Send failed" errorsVerify Graph API send permission; check OAuth token
Template variables not replacingEnsure correct syntax %{variable} with curly braces
Emails going to spamConfigure SPF, DKIM, DMARC for the sending domain

Best Practices

  1. One email account per department — cleaner routing and management
  2. Test after OAuth re-authorization — always verify fetch/send after token refresh
  3. Monitor "Last Fetch" timestamps — stale timestamps indicate fetching is broken
  4. Keep auto-response templates brief — acknowledge receipt without overwhelming clients
  5. Include ticket number in subject — ensures proper threading
  6. Set up mailbox monitoring — alert if emails stop being fetched for more than 5 minutes