Bileto allows you to configure mailboxes to receive emails. These emails are retrieved with IMAP and can be transformed in tickets.
The Mailbox
entity stores the information about the mailboxes.
Mailboxes are managed in the MailboxesController
.
This controller allows you, among the rest, to collect the emails from the mailboxes.
When emails are collected, the first thing that Bileto does is to fetch the “Unseen” emails from the mailboxes.
It is done in the FetchMailboxesHandler
.
Its job is to fetch the emails, save them as MailboxEmail
entities, and delete them.
If deletion fails, the emails are marked as “Seen”.
Once the emails are fetched, it's time to import tickets from the MailboxEmail
s.
This is the job of the CreateTicketsFromMailboxEmailsHandler
.
For each MailboxEmail
:
- it gets the requester (i.e. the
From
header); - it gets the default organization of the requester;
- it detects a potential ticket to which the email might reply;
- if it detects a ticket, it checks that the requester can answer to it and that it is not closed;
- otherwise it checks the requester has the permission to create tickets in the organization and it creates one based on the
Subject
and theBody
of the email; - it saves attachments as
MessageDocument
s; - finally, it deletes the
MailboxEmail
from the database.
If anything goes wrong during this process, the error is logged in the relevant MailboxEmail
lastError
field.
To detect the ticket to which the email reply, we use two techniques:
- we track the
Message-ID
header from the sent notifications (seeSendMessageEmailHandler
). If the email answers to an ID that we track, we load the corresponding ticket. - otherwise, we search for a
[#ID]
substring in the subject of the email.
You don’t have to fetch the emails manually each time you receive an email to the support. Indeed, the previous jobs are scheduled to be executed every minute.
It’s declared in the DefaultScheduleProvider
.