Skip to content

Documentation

PHP SDK: Mail: messages and attachments

Create an address with the "+" button at the top of Incoming Mail. Send messages to it, forward messages you receive, or add the address to CC. Restricting senders is optional: an empty list accepts any address. The sender filter is in the address's advanced settings. In a published scenario, open Incoming Mail and connect the address. The scenario starts after the message has been checked. This SDK cannot send email.

All examples below run inside run(\Sdk\Context $ctx). Check available(): a trial run cannot access a real message.

available

available(): bool

Whether this run has a verified message. Returns false for manual and trial runs.

if (!$ctx->mail()->available()) return;

current

current(): array

The current message's subject, sender, text, attachments, and retention period. Internal headers and other recipients are not exposed. Text is limited to 1 MiB; text_truncated tells you when it was shortened.

if ($ctx->mail()->available()) {
    $message = $ctx->mail()->current();
    $ctx->log($message['subject']);
}

text

text(): string

Get the plain text of the message without HTML.

if ($ctx->mail()->available()) {
    $text = $ctx->mail()->text();
    $ctx->log('Characters in message: '.mb_strlen($text));
}

attachments

attachments(): array

The verified attachments, with id, name, mime, and size. Download links require access to the current workspace.

if ($ctx->mail()->available()) {
    foreach ($ctx->mail()->attachments() as $file) {
        $ctx->log($file['name']);
    }
}

document

document(string $id): Document

Extract text, Excel sheets, Word tables, or PDF pages from an attachment belonging to this message. Links in the document are not opened automatically. No more than eight documents can be parsed per run.

if ($ctx->mail()->available()) {
    foreach ($ctx->mail()->attachments() as $file) {
        $document = $ctx->mail()->document($file['id']);
        if (!$document->complete()) $ctx->fail('Split the large document into smaller parts');
        foreach ($document->rows() as $row) {
            $ctx->log(json_encode($row, JSON_UNESCAPED_UNICODE));
        }
    }
}

attachment

attachment(string $id): string

Read the original attachment bytes, up to 10 MiB. For spreadsheets and text, document() is more convenient. Access ends when the message is deleted, retention expires, or permissions are removed.

if ($ctx->mail()->available()) {
    foreach ($ctx->mail()->attachments() as $file) {
        $bytes = $ctx->mail()->attachment($file['id']);
        $ctx->log('Bytes received: '.strlen($bytes));
    }
}

Mail attachments are available only while processing their associated message. A manual run cannot use the ID of a different message. Replay does not read live mail.

Processing on your own agent

The source settings determine where a scenario runs. If you select your agent, Akmelo sends it a job, and the agent requests the message and attachments over a protected connection. SDK code stays the same. document() parses the file with the agent's local document service, including calculation of supported Excel formulas. The job does not contain a copy of the message. Access is checked on every read and ends on expiry, deletion, disconnection, or permission revocation. The first read requires a connection to the platform.

The message first arrives in Akmelo's cloud inbox and stays there for the selected retention period. Your agent runs the scenario; it does not replace the inbox. Agent results are sent to the platform only when mirroring is enabled. Records and exports explicitly created by a scenario have their own retention periods.