Skip to main content
Communication

Incoming Mails

Process incoming email messages, convert them to support tickets, and handle Mailgun webhook delivery events.

Base URL: /api/v1/incoming_mails

Auth required: Yes (auth:api) for all endpoints.

Incoming mails are email messages received by the system inbox. They can be converted to tickets or added as replies to existing tickets.


Model Properties

Incoming Mail

Property Type Description
id integer Unique identifier
message_id string Email message ID from the mail server (e.g. <abc@mail.example.com>)
sender string Sender email address
recipient string Recipient email address (the inbox that received this mail)
subject string Email subject line
body text Email body content (HTML or plain text)
ticket_id integer FK to tickets. Set when the mail has been converted to a ticket or reply
reply_to_closed_ticket boolean Whether this mail is a reply to an already-closed ticket
analysis text Internal analysis data (used for routing suggestions)
notified boolean Whether internal team has been notified of this incoming mail
created_at datetime Creation timestamp (when the mail was received)
updated_at datetime Last update timestamp

Incoming mails are receive-only: they cannot be created via the API. The API allows listing and deleting, or converting them to tickets/replies.


GET /v1/incoming_mails

List incoming mails, with optional filtering.

Query parameters:

Parameter Type Description
filter string Optional filter: out_ticket (mails without a ticket), reply_to_closed_ticket (replies to closed tickets)

Without a filter, returns all incoming mails paginated at 100 per page.

Response 200: Paginated list of incoming mail objects.

Examples:

curl -s -X GET "https://your-instance.bluerocktel.net/api/v1/incoming_mails?filter=out_ticket" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Accept: application/json"
import requests

response = requests.get(
    "https://your-instance.bluerocktel.net/api/v1/incoming_mails",
    params={"filter": "out_ticket"},
    headers={"Authorization": f"Bearer {token}", "Accept": "application/json"},
)
mails = response.json()
use Illuminate\Support\Facades\Http;

$response = Http::withToken($token)
    ->acceptJson()
    ->get('https://your-instance.bluerocktel.net/api/v1/incoming_mails', [
        'filter' => 'out_ticket',
    ]);

$mails = $response->json();
const response = await fetch(
  "https://your-instance.bluerocktel.net/api/v1/incoming_mails?filter=outTicket",
  {
    headers: {
      Authorization: `Bearer ${token}`,
      Accept: "application/json",
    },
  }
);
const mails = await response.json();

DELETE /v1/incoming_mails/{incoming_mail}

Delete an incoming mail.

URL parameters:

Parameter Type Description
incoming_mail integer Incoming mail ID

Response 201: Success message. Response 404: Not found.

Examples:

curl -s -X DELETE "https://your-instance.bluerocktel.net/api/v1/incoming_mails/87" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Accept: application/json"
import requests

response = requests.delete(
    "https://your-instance.bluerocktel.net/api/v1/incoming_mails/87",
    headers={"Authorization": f"Bearer {token}", "Accept": "application/json"},
)
$response = Http::withToken($token)
    ->acceptJson()
    ->delete('https://your-instance.bluerocktel.net/api/v1/incoming_mails/87');
const response = await fetch(
  "https://your-instance.bluerocktel.net/api/v1/incoming_mails/87",
  {
    method: "DELETE",
    headers: {
      Authorization: `Bearer ${token}`,
      Accept: "application/json",
    },
  }
);

PUT /v1/incoming_mails/{incoming_mail}/ticket

Convert an incoming mail into a new ticket.

URL parameters:

Parameter Type Description
incoming_mail integer Incoming mail ID

Body (JSON):

Field Type Required Description
customer_id integer Yes Customer to associate the ticket with

Processing:

  1. Creates a Contact if one does not already exist for the sender's email.
  2. Creates a Ticket with the sanitized subject and body from the email.
  3. Moves email attachments to the ticket.
  4. Marks the mail as processed (ticket_id set, reply_to_closed_ticket = false).

Response 201: Created ticket object. Response 400: Validation error. Response 404: Mail or customer not found.

Examples:

curl -s -X PUT "https://your-instance.bluerocktel.net/api/v1/incoming_mails/87/ticket" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{"customer_id": 12}'
import requests

response = requests.put(
    "https://your-instance.bluerocktel.net/api/v1/incoming_mails/87/ticket",
    headers={"Authorization": f"Bearer {token}", "Accept": "application/json"},
    json={"customer_id": 12},
)
ticket = response.json()
$response = Http::withToken($token)
    ->acceptJson()
    ->put('https://your-instance.bluerocktel.net/api/v1/incoming_mails/87/ticket', [
        'customer_id' => 12,
    ]);

$ticket = $response->json();
const response = await fetch(
  "https://your-instance.bluerocktel.net/api/v1/incoming_mails/87/ticket",
  {
    method: "PUT",
    headers: {
      Authorization: `Bearer ${token}`,
      Accept: "application/json",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ customer_id: 12 }),
  }
);
const ticket = await response.json();

PUT /v1/incoming_mails/{incoming_mail}/reply

Add an incoming mail as a reply to an existing ticket (determined by the mail's ticket_id).

URL parameters:

Parameter Type Description
incoming_mail integer Incoming mail ID

Body: None. The ticket is inferred from the mail's ticket_id.

Processing:

  1. Creates a Contact if needed.
  2. Creates a Reply on the ticket.
  3. Increments ticket exchange count.
  4. Moves email attachments to the ticket.
  5. Cancels any pending ticket closure.
  6. Records a tracking event.

Response 201: Created reply (ticket) object. Response 404: Mail or ticket not found.

Examples:

curl -s -X PUT "https://your-instance.bluerocktel.net/api/v1/incoming_mails/87/reply" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Accept: application/json"
import requests

response = requests.put(
    "https://your-instance.bluerocktel.net/api/v1/incoming_mails/87/reply",
    headers={"Authorization": f"Bearer {token}", "Accept": "application/json"},
)
reply = response.json()
$response = Http::withToken($token)
    ->acceptJson()
    ->put('https://your-instance.bluerocktel.net/api/v1/incoming_mails/87/reply');

$reply = $response->json();
const response = await fetch(
  "https://your-instance.bluerocktel.net/api/v1/incoming_mails/87/reply",
  {
    method: "PUT",
    headers: {
      Authorization: `Bearer ${token}`,
      Accept: "application/json",
    },
  }
);
const reply = await response.json();

Mailgun Webhook Endpoints

These endpoints receive Mailgun delivery event notifications. They do NOT require authentication.

Endpoint Event
POST /mg-clicked Email link clicked
POST /mg-complained Spam complaint
POST /mg-delivered Email delivered
POST /mg-opened Email opened
POST /mg-permanent-fail Permanent delivery failure
POST /mg-temporary-fail Temporary delivery failure

Mail Report Webhook

POST /mail-report

Receive a mail delivery report from external mail systems.

Auth required: No.

Body: Mail report payload.