# Retrieve Received Attachment

> GET /emails/receiving/:id/attachments/:attachment_id — fetch a single attachment from a received email.

`GET /emails/receiving/:id/attachments/:attachment_id`

Download a single attachment from a received email by its id. Unlike most API endpoints, this returns the **raw file bytes** as a binary download — not a JSON object. Use the `Content-Type` and `Content-Disposition` of the response to handle the file.

## Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | Yes | The id of the received email. |
| `attachment_id` | string | Yes | The id of the attachment to download. |

## Response

On success the response body is the raw attachment bytes. The `Content-Type` header carries the file's MIME type (render-capable types such as HTML/SVG are served as `application/octet-stream` for safety), and a `Content-Disposition: attachment` header carries the original filename. There is no JSON envelope.

```bash
HTTP/1.1 200 OK
Content-Type: image/png
Content-Disposition: attachment; filename="avatar.png"
X-Content-Type-Options: nosniff

<binary file bytes>
```

## Request

**Node.js**

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

const mb = new SendPing('mb_xxxxxxxxx');

const { data, error } = await mb.emails.receiving.getAttachment('4ef9a417-02e9-4d39-ad75-9611e0fcc33c', '2a0c9ce0-3112-4728-976e-47ddcd16a318');
console.log({ data, error });
```

**Ruby**

```ruby
require "sendping"

SendPing.api_key = "mb_xxxxxxxxx"

SendPing::Emails::Receiving.get_attachment("4ef9a417-02e9-4d39-ad75-9611e0fcc33c", "2a0c9ce0-3112-4728-976e-47ddcd16a318")
```

**PHP**

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

use SendPing\SendPing;

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

$sendping->emails->receiving->getAttachment('4ef9a417-02e9-4d39-ad75-9611e0fcc33c', '2a0c9ce0-3112-4728-976e-47ddcd16a318');
```

**Python**

```python
import sendping

sendping.api_key = "mb_xxxxxxxxx"

sendping.Emails.Receiving.get_attachment("4ef9a417-02e9-4d39-ad75-9611e0fcc33c", "2a0c9ce0-3112-4728-976e-47ddcd16a318")
```

**Go**

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

client := sendping.NewClient("mb_xxxxxxxxx")

data, err := client.Emails.Receiving.GetAttachment("4ef9a417-02e9-4d39-ad75-9611e0fcc33c", "2a0c9ce0-3112-4728-976e-47ddcd16a318")
```

**Rust**

```rust
use sendping::SendPing;

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

let _bytes = mb.emails.receiving.get_attachment("4ef9a417-02e9-4d39-ad75-9611e0fcc33c", "2a0c9ce0-3112-4728-976e-47ddcd16a318").await?;
```

**Java**

```java
import co.sendping.SendPing;

SendPing sendping = new SendPing("mb_xxxxxxxxx");

byte[] data = sendping.emails().receiving().getAttachment(
        "4ef9a417-02e9-4d39-ad75-9611e0fcc33c",
        "2a0c9ce0-3112-4728-976e-47ddcd16a318");
```

**.NET**

```csharp
using SendPing;

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

var resp = await sendping.ReceivedEmailGetAttachmentAsync(
    "4ef9a417-02e9-4d39-ad75-9611e0fcc33c",
    "2a0c9ce0-3112-4728-976e-47ddcd16a318");
```

**cURL**

```bash
curl -X GET 'https://www.sendping.co/api/emails/receiving/4ef9a417-02e9-4d39-ad75-9611e0fcc33c/attachments/2a0c9ce0-3112-4728-976e-47ddcd16a318' \
  -H 'Authorization: Bearer mb_xxxxxxxxx'
```

**CLI**

```bash
sendping emails receiving attachment 4ef9a417-02e9-4d39-ad75-9611e0fcc33c 2a0c9ce0-3112-4728-976e-47ddcd16a318
```

## Errors

Returns `not_found` (404) if the received email or the attachment does not exist for your account, or if the attachment bytes were not stored for this email. See the [error reference](https://www.sendping.co/docs/api/errors).
