# Attachments

> Attach files to an email as base64 content or a hosted URL, with per-file and total size limits.

Add files to an email with the `attachments` array. Each attachment is either inlined as **base64** `content` or referenced by a hosted **`path`** URL that SendPing fetches when the email is sent.

## Attachment fields

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `filename` | string | Yes | The name the file is presented with in the recipient's mail client (e.g. `invoice.pdf`). |
| `content` | string | No | The file contents, base64-encoded. Provide either `content` **or** `path`. |
| `path` | string | No | A hosted URL SendPing fetches at send time. Provide either `path` **or** `content`. The fetch is SSRF-guarded. |
| `content_type` | string | No | Optional MIME type for the attachment (e.g. `application/pdf`). Inferred from the filename when omitted. |
| `content_id` | string | No | Embeds the attachment as an inline image; reference it in your HTML via `<img src="cid:...">`. Only meaningful when the attachment is an image. |

> **Warning:** Each attachment must provide exactly one of `content` or `path`. An attachment with neither is rejected.

## Size limits

| Limit | Value |
| --- | --- |
| Per attachment | up to 25 MB |
| Total per email | up to 40 MB |

These limits cover the decoded bytes. Note that base64 encoding inflates the payload by roughly 33%, so a 25 MB file is about 34 MB of `content` in the request body. For large files, prefer `path` so SendPing streams the bytes server-side.

> **Warning:** Attachments are **not supported on the batch endpoint** ([POST /emails/batch](https://www.sendping.co/docs/emails/batch)). To send an email with an attachment, use a single [POST /emails](https://www.sendping.co/docs/api/emails-send) request.

## Send with an attachment (hosted URL)

The simplest form points `path` at a hosted file — SendPing fetches it at send time, so you never base64-encode anything yourself.

**Node.js**

```js
import { SendPing } from 'sendping';

const mb = new SendPing('mb_xxxxxxxxx');

const { data, error } = await mb.emails.send({
  "from": "Acme <hello@yourdomain.com>",
  "to": ["delivered@test.sendping.co"],
  "subject": "Your invoice",
  "html": "<p>Invoice attached.</p>",
  "attachments": [
    {
      "filename": "invoice.pdf",
      "path": "https://yourdomain.com/invoices/invoice.pdf"
    }
  ]
});
console.log({ data, error });
```

**Ruby**

```ruby
require "sendping"

SendPing.api_key = "mb_xxxxxxxxx"

SendPing::Emails.send({
  "from": "Acme <hello@yourdomain.com>",
  "to": [
    "delivered@test.sendping.co"
  ],
  "subject": "Your invoice",
  "html": "<p>Invoice attached.</p>",
  "attachments": [
    {
      "filename": "invoice.pdf",
      "path": "https://yourdomain.com/invoices/invoice.pdf"
    }
  ]
})
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

use SendPing\SendPing;

$sendping = SendPing::client('mb_xxxxxxxxx');

$sendping->emails->send([
  'from' => "Acme <hello@yourdomain.com>",
  'to' => [
    "delivered@test.sendping.co"
  ],
  'subject' => "Your invoice",
  'html' => "<p>Invoice attached.</p>",
  'attachments' => [
    [
      'filename' => "invoice.pdf",
      'path' => "https://yourdomain.com/invoices/invoice.pdf"
    ]
  ]
]);
```

**Python**

```python
import sendping

sendping.api_key = "mb_xxxxxxxxx"

sendping.Emails.send({
  "from": "Acme <hello@yourdomain.com>",
  "to": [
    "delivered@test.sendping.co"
  ],
  "subject": "Your invoice",
  "html": "<p>Invoice attached.</p>",
  "attachments": [
    {
      "filename": "invoice.pdf",
      "path": "https://yourdomain.com/invoices/invoice.pdf"
    }
  ]
})
```

**Go**

```go
import "github.com/shekhu10/sendping-sdks/sendping-go"

client := sendping.NewClient("mb_xxxxxxxxx")

sent, err := client.Emails.Send(&sendping.SendEmailRequest{
    From:    "Acme <hello@yourdomain.com>",
    To:      []string{"delivered@test.sendping.co"},
    Subject: "Your invoice",
    Html:    "<p>Invoice attached.</p>",
    Attachments: []sendping.Attachment{
        {
            Filename: "invoice.pdf",
            Path:     "https://yourdomain.com/invoices/invoice.pdf",
        },
    },
})
```

**Rust**

```rust
use sendping::{Attachment, SendEmailOptions, SendPing};

let mb = SendPing::new("mb_xxxxxxxxx");

let params = SendEmailOptions::new(
    "Acme <hello@yourdomain.com>",
    ["delivered@test.sendping.co"],
    "Your invoice",
)
.with_html("<p>Invoice attached.</p>")
.with_attachment(Attachment::from_path(
        "invoice.pdf",
        "https://yourdomain.com/invoices/invoice.pdf",
    ));
let _sent = mb.emails.send(params).await?;
```

**Java**

```java
import co.sendping.SendPing;
import co.sendping.SendPingResponse;
import co.sendping.requests.Attachment;
import co.sendping.requests.SendEmailRequest;

SendPing sendping = new SendPing("mb_xxxxxxxxx");

SendEmailRequest request = SendEmailRequest.builder()
        .from("Acme <hello@yourdomain.com>")
        .to("delivered@test.sendping.co")
        .subject("Your invoice")
        .html("<p>Invoice attached.</p>")
        .attachment(Attachment.builder()
                .filename("invoice.pdf")
                .path("https://yourdomain.com/invoices/invoice.pdf")
                .build())
        .build();

SendPingResponse response = sendping.emails().send(request);
```

**.NET**

```csharp
using SendPing;

ISendPing sendping = SendPingClient.Create("mb_xxxxxxxxx");

var resp = await sendping.EmailSendAsync(new EmailMessage
{
    From = "Acme <hello@yourdomain.com>",
    To = "delivered@test.sendping.co",
    Subject = "Your invoice",
    HtmlBody = "<p>Invoice attached.</p>",
    Attachments = new List<EmailAttachment>
    {
        new()
        {
            Filename = "invoice.pdf",
            Path = "https://yourdomain.com/invoices/invoice.pdf",
        },
    },
});
```

**cURL**

```bash
curl -X POST 'https://www.sendping.co/api/emails' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "from": "Acme <hello@yourdomain.com>",
  "to": ["delivered@test.sendping.co"],
  "subject": "Your invoice",
  "html": "<p>Invoice attached.</p>",
  "attachments": [
    {
      "filename": "invoice.pdf",
      "path": "https://yourdomain.com/invoices/invoice.pdf"
    }
  ]
}'
```

> **Note:** A `path` URL is fetched through an SSRF-guarded client and must return the file with a 2xx status. If the fetch fails or the file exceeds the size limit, the send is rejected with a `422 invalid_attachment`. Base64 `content` is sized before anything is sent, so an over-size file is rejected without consuming quota.

## Send with base64 content

Or inline the bytes directly as base64 `content` — useful for files you generate in memory and never host.

**Node.js**

```js
import { SendPing } from 'sendping';

const mb = new SendPing('mb_xxxxxxxxx');

const { data, error } = await mb.emails.send({
  "from": "Acme <hello@yourdomain.com>",
  "to": ["delivered@test.sendping.co"],
  "subject": "Your invoice",
  "html": "<p>Invoice attached.</p>",
  "attachments": [
    {
      "filename": "invoice.pdf",
      "content": "JVBERi0xLjQKJ...base64...",
      "content_type": "application/pdf"
    }
  ]
});
console.log({ data, error });
```

**Ruby**

```ruby
require "sendping"

SendPing.api_key = "mb_xxxxxxxxx"

SendPing::Emails.send({
  "from": "Acme <hello@yourdomain.com>",
  "to": [
    "delivered@test.sendping.co"
  ],
  "subject": "Your invoice",
  "html": "<p>Invoice attached.</p>",
  "attachments": [
    {
      "filename": "invoice.pdf",
      "content": "JVBERi0xLjQKJ...base64...",
      "content_type": "application/pdf"
    }
  ]
})
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

use SendPing\SendPing;

$sendping = SendPing::client('mb_xxxxxxxxx');

$sendping->emails->send([
  'from' => "Acme <hello@yourdomain.com>",
  'to' => [
    "delivered@test.sendping.co"
  ],
  'subject' => "Your invoice",
  'html' => "<p>Invoice attached.</p>",
  'attachments' => [
    [
      'filename' => "invoice.pdf",
      'content' => "JVBERi0xLjQKJ...base64...",
      'content_type' => "application/pdf"
    ]
  ]
]);
```

**Python**

```python
import sendping

sendping.api_key = "mb_xxxxxxxxx"

sendping.Emails.send({
  "from": "Acme <hello@yourdomain.com>",
  "to": [
    "delivered@test.sendping.co"
  ],
  "subject": "Your invoice",
  "html": "<p>Invoice attached.</p>",
  "attachments": [
    {
      "filename": "invoice.pdf",
      "content": "JVBERi0xLjQKJ...base64...",
      "content_type": "application/pdf"
    }
  ]
})
```

**Go**

```go
import "github.com/shekhu10/sendping-sdks/sendping-go"

client := sendping.NewClient("mb_xxxxxxxxx")

sent, err := client.Emails.Send(&sendping.SendEmailRequest{
    From:    "Acme <hello@yourdomain.com>",
    To:      []string{"delivered@test.sendping.co"},
    Subject: "Your invoice",
    Html:    "<p>Invoice attached.</p>",
    Attachments: []sendping.Attachment{
        {
            Filename:    "invoice.pdf",
            Content:     "JVBERi0xLjQKJ...base64...",
            ContentType: "application/pdf",
        },
    },
})
```

**Rust**

```rust
use sendping::{Attachment, SendEmailOptions, SendPing};

let mb = SendPing::new("mb_xxxxxxxxx");

let params = SendEmailOptions::new(
    "Acme <hello@yourdomain.com>",
    ["delivered@test.sendping.co"],
    "Your invoice",
)
.with_html("<p>Invoice attached.</p>")
.with_attachment(Attachment::from_content("invoice.pdf", "JVBERi0xLjQKJ...base64...")
        .with_content_type("application/pdf"));
let _sent = mb.emails.send(params).await?;
```

**Java**

```java
import co.sendping.SendPing;
import co.sendping.SendPingResponse;
import co.sendping.requests.Attachment;
import co.sendping.requests.SendEmailRequest;

SendPing sendping = new SendPing("mb_xxxxxxxxx");

SendEmailRequest request = SendEmailRequest.builder()
        .from("Acme <hello@yourdomain.com>")
        .to("delivered@test.sendping.co")
        .subject("Your invoice")
        .html("<p>Invoice attached.</p>")
        .attachment(Attachment.builder()
                .filename("invoice.pdf")
                .content("JVBERi0xLjQKJ...base64...")
                .contentType("application/pdf")
                .build())
        .build();

SendPingResponse response = sendping.emails().send(request);
```

**.NET**

```csharp
using SendPing;

ISendPing sendping = SendPingClient.Create("mb_xxxxxxxxx");

var resp = await sendping.EmailSendAsync(new EmailMessage
{
    From = "Acme <hello@yourdomain.com>",
    To = "delivered@test.sendping.co",
    Subject = "Your invoice",
    HtmlBody = "<p>Invoice attached.</p>",
    Attachments = new List<EmailAttachment>
    {
        new()
        {
            Filename = "invoice.pdf",
            Content = "JVBERi0xLjQKJ...base64...",
            ContentType = "application/pdf",
        },
    },
});
```

**cURL**

```bash
curl -X POST 'https://www.sendping.co/api/emails' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "from": "Acme <hello@yourdomain.com>",
  "to": ["delivered@test.sendping.co"],
  "subject": "Your invoice",
  "html": "<p>Invoice attached.</p>",
  "attachments": [
    {
      "filename": "invoice.pdf",
      "content": "JVBERi0xLjQKJ...base64...",
      "content_type": "application/pdf"
    }
  ]
}'
```
