# Email Integration

Drako Tickets supports two email directions:

* **Outbound (SMTP)** — send reply notifications and ticket confirmations to users
* **Inbound (IMAP)** — poll a mailbox so that email replies automatically append to the correct ticket

Both are configured in **Dashboard → Settings → Mail Server** and **Inbound Email**.

***

## Outbound mail (SMTP)

{% stepper %}
{% step %}

#### Gather your SMTP credentials

You can use any SMTP provider. Common choices:

| Provider                | Host                 | Port           | Notes                                                                                   |
| ----------------------- | -------------------- | -------------- | --------------------------------------------------------------------------------------- |
| Gmail                   | `smtp.gmail.com`     | 587            | Requires an [App Password](https://myaccount.google.com/apppasswords) if 2FA is enabled |
| Outlook / Microsoft 365 | `smtp.office365.com` | 587            | Use your full email as the username                                                     |
| Mailgun                 | `smtp.mailgun.org`   | 587            | Use SMTP credentials from your Mailgun domain                                           |
| SendGrid                | `smtp.sendgrid.net`  | 587            | Username is always `apikey`, password is your API key                                   |
| Custom / self-hosted    | your server          | 25 / 465 / 587 | Ensure port is open and not blocked by your host                                        |
| {% endstep %}           |                      |                |                                                                                         |

{% step %}

#### Configure in the dashboard

Go to **Settings → Mail Server** and fill in:

| Field         | Description                                                              |
| ------------- | ------------------------------------------------------------------------ |
| SMTP Host     | Your provider's hostname, e.g. `smtp.gmail.com`                          |
| SMTP Port     | Usually `587` (STARTTLS) or `465` (SSL)                                  |
| Secure (SSL)  | Enable if using port 465                                                 |
| Username      | Your email address or SMTP username                                      |
| Password      | Your SMTP password or app password                                       |
| From Address  | The address emails are sent from, e.g. `support@yourcompany.com`         |
| From Name     | Display name shown in the recipient's inbox, e.g. `Your Company Support` |
| {% endstep %} |                                                                          |

{% step %}

#### Test the connection

Click **Test SMTP Connection** to send a test message to yourself. If it fails, check:

* The host and port are correct
* Your firewall or hosting provider allows outbound SMTP on that port
* You are using an App Password if your account has 2FA enabled
  {% endstep %}

{% step %}

#### Enable SMTP

Toggle **Enable SMTP** on and click **Save**. Outbound notifications will now be sent when a technician replies to a ticket.
{% endstep %}
{% endstepper %}

***

## Inbound email (IMAP)

When IMAP is enabled, Drako Tickets polls your mailbox on a schedule. Emails are matched to existing tickets by the `[TK-XXXX]` reference in the subject line. If no match is found a new ticket is created.

{% stepper %}
{% step %}

#### Set up a dedicated support mailbox

Create a dedicated email address for support, e.g. `support@yourcompany.com`. This keeps your personal inbox separate and makes filtering easier.
{% endstep %}

{% step %}

#### Enable IMAP access on your mailbox

| Provider                | How to enable                                                                                                                                           |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Gmail                   | Settings → See all settings → Forwarding and POP/IMAP → Enable IMAP. If 2FA is on, create an [App Password](https://myaccount.google.com/apppasswords). |
| Outlook / Microsoft 365 | Settings → Mail → Sync email → Enable IMAP.                                                                                                             |
| Other providers         | Refer to your provider's documentation.                                                                                                                 |
| {% endstep %}           |                                                                                                                                                         |

{% step %}

#### Configure in the dashboard

Go to **Settings → Inbound Email** and fill in:

| Field         | Description                                          |
| ------------- | ---------------------------------------------------- |
| IMAP Host     | Your provider's IMAP hostname, e.g. `imap.gmail.com` |
| IMAP Port     | Usually `993` (SSL) or `143` (STARTTLS)              |
| Secure (SSL)  | Enable for port 993                                  |
| Username      | Your mailbox email address                           |
| Password      | Your IMAP password or app password                   |
| Mailbox       | The folder to poll, usually `INBOX`                  |
| Poll Interval | How often to check for new mail (minimum 1 minute)   |
| {% endstep %} |                                                      |

{% step %}

#### Test the connection

Click **Test IMAP Connection** to verify the credentials. A successful test means Drako Tickets can connect and read the mailbox.
{% endstep %}

{% step %}

#### Enable IMAP polling

Toggle **Enable IMAP** on and click **Save**. The poller starts immediately and will run on the configured interval.
{% endstep %}
{% endstepper %}

### How ticket matching works

When an email arrives, DrakoTickets looks for a `[TK-XXXX]` tag in the subject line (e.g. `Re: Your ticket [TK-0042]`). If found, the email body is appended as a new comment on that ticket. If no tag is found, a new ticket is created and a confirmation email is sent to the sender.

{% hint style="info" %}
**Tip:** The confirmation email template is customisable in **Settings → Email Templates**.
{% endhint %}

***

## Email templates

Go to **Settings → Email Templates** to customise:

* **Confirmation email** — sent to the requester when a new ticket is created via email
* **Reply email** — sent to the requester when a technician replies
* **Global signature** — appended to all outbound emails

Templates support the following variables:

| Variable             | Description                    |
| -------------------- | ------------------------------ |
| `{{ticket_number}}`  | The ticket number, e.g. `0042` |
| `{{ticket_title}}`   | The ticket subject / title     |
| `{{requester_name}}` | The requester's display name   |
| `{{from_name}}`      | The configured From Name       |
