Skip to content

Latest commit

 

History

History
48 lines (32 loc) · 2.42 KB

email-collector.md

File metadata and controls

48 lines (32 loc) · 2.42 KB

Email collector

Bileto allows you to configure mailboxes to receive emails. These emails are retrieved with IMAP and can be transformed in tickets.

The Mailbox entity

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.

The FetchMailboxes handler

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”.

The CreateTicketsFromMailboxEmails handler

Once the emails are fetched, it's time to import tickets from the MailboxEmails. This is the job of the CreateTicketsFromMailboxEmailsHandler.

For each MailboxEmail:

  1. it gets the requester (i.e. the From header);
  2. it gets the default organization of the requester;
  3. it detects a potential ticket to which the email might reply;
  4. if it detects a ticket, it checks that the requester can answer to it and that it is not closed;
  5. otherwise it checks the requester has the permission to create tickets in the organization and it creates one based on the Subject and the Body of the email;
  6. it saves attachments as MessageDocuments;
  7. 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 (see SendMessageEmailHandler). 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.

Scheduling

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.