---
title: "Mail and External Services"
description: "Mail sending, FTP operations, REST and SOAP clients, and ZIP archive management."
canonical_url: "https://www.zeyos.com/zymba/zymba-guide/platform-integration/mail-files"
markdown_url: "https://www.zeyos.com/ai/guide/zymba/zymba-guide/platform-integration/mail-files.md"
section: "zymba-guide"
authority: "draft-guide"
language: "en"
source_repository: "zeyos/guide"
source_path: "docs/zymba/08-platform-integration/mail-files.md"
source_revision: "cce886a8da98cd124ee3644711085bbdcf1a87ce"
---

# Mail and External Services

## @Mail — email

### @Mail.SimpleMessage — plain text email

```zymba
$msg = new @Mail.SimpleMessage();
$msg.setTo("user@example.com");
$msg.setFrom("noreply@company.com");
$msg.setSubject("Welcome!");
$msg.setBody("Hello, welcome to our platform.");
$msg.setReplyTo("support@company.com");

@ZeyOS.queueMail($msg);
```

### @Mail.MultipartMessage — HTML email with attachments

```zymba
$msg = new @Mail.MultipartMessage();
$msg.setTo("user@example.com");
$msg.setSubject("Your Report");
$msg.setHTMLBody("<h1>Report</h1><p>See attachment.</p>");
$msg.setTextBody("Report - see attachment.");
$msg.addAttachment("/path/to/report.pdf", "report.pdf", "application/pdf");
$msg.addAttachment($csvData, "data.csv", "text/csv");

@ZeyOS.queueMail($msg);
```

---

## @FTP.Client — FTP operations (30 methods)

```zymba
$ftp = new @FTP.Client();
$ftp.connect("ftp.example.com", 21);
$ftp.login("user", "password");

// Download
$content = $ftp.get("/remote/file.txt");
$ftp.download("/remote/file.txt", "/local/file.txt");

// Upload
$ftp.put("/remote/file.txt", $content);
$ftp.upload("/local/file.txt", "/remote/file.txt");

// Directory operations
$files = $ftp.listFiles("/remote/dir");
$ftp.createDirectory("/remote/newdir");
$ftp.deleteFile("/remote/old.txt");

$ftp.close();
```

---

## @REST.Client — REST API client (6 methods)

```zymba
$client = new @REST.Client("https://api.example.com");

$response = $client.get("/users");
$response = $client.post("/users", [name: "Alice"]);
$response = $client.put("/users/1", [name: "Alice Updated"]);
$response = $client.delete("/users/1");
```

---

## @SOAP.Client — SOAP web service client (8 methods)

```zymba
$client = new @SOAP.Client("https://service.example.com/api?wsdl");

$result = $client.call("GetUser", [userId: 123]);
echo $result.name;
```

---

## @ZIP.Archive — ZIP file manipulation (30 methods)

```zymba
$zip = new @ZIP.Archive();

// Create a new archive
$zip.open("/path/to/archive.zip", @ZIP.Archive.CREATE);
$zip.addFile("/path/to/file.txt", "file.txt");
$zip.addString("Hello World", "hello.txt");
$zip.close();

// Read an existing archive
$zip.open("/path/to/archive.zip");
$content = $zip.readFile("hello.txt");
$files   = $zip.listFiles();
$zip.extractAll("/path/to/output");
$zip.close();
```

---

## Practical patterns

### Complete API service handler

```zymba
include 'zymba:sql,var,http';

// Guard clauses
unless (@HTTP.getRequestMethod() == "POST") {
    @HTTP.setStatusCode(405);
    echo @Var.toJSON([error: "Method not allowed"]);
    return;
}

// Parse input
$input = @HTTP.getRequestBody();
$data  = null;
try {
    $data = @Var.fromJSON($input);
} catch ($e) {
    @HTTP.setStatusCode(400);
    echo @Var.toJSON([error: "Invalid JSON"]);
    return;
}

// Database operations
$db = @ZeyOS.selectDatabase();
with ($db.selectTransaction()) {
    $contact = new @ZeyOS.Object("contacts");
    $contact.setFields([
        name:   $data.name,
        email:  $data.email,
        status: 1
    ]);
    $contact.save();

    $tags = $contact.selectTags();
    $tags.addTags($data.tags ?? []);
}

@HTTP.setHeader("Content-Type", "application/json");
echo @Var.toJSON([success: true, id: $contact.getID()]);
```

### Batch import with transaction

```zymba
include 'zymba:sql,var';

$db       = @ZeyOS.selectDatabase();
$imported = 0;
$errors   = [];

with (new @ZeyOS.TransactionContext) {
    for ($records as $record) {
        try {
            $obj = new @ZeyOS.Object("contacts");
            $obj.setFields($record);
            $obj.save();
            $imported++;
        } catch ($e) {
            $errors[] = [record: $record, error: $e.getMessage()];
        }
    }
}

echo @Var.toJSON([imported: $imported, errors: $errors]);
```
