/mail/{id}/attachments
GETGet a list of all attachments for a specific email.
Description
This endpoint retrieves metadata about all attachments associated with a specific email. It returns information about each attachment including its ID, filename, file extension, and size. Use this endpoint to get an overview of all attachments before downloading them individually.
Attachment Overview
This endpoint only returns metadata about the attachments. To download the actual attachment files, use the /api/mail/{id}/attachment/{n} endpoint with the specific attachment ID.
Interactive API Tester
Try it out
Path Parameters
The request requires a path parameter to identify the email.
| Parameter | Type | Required | Description |
|---|---|---|---|
id |
string | Yes | The unique identifier of the email. Must be a 32-character hexadecimal string (e.g., "a1b2c3d4e5f6789012345678abcdef90"). |
Response
Upon success, the endpoint returns a 200 OK response with details about all attachments for the specified email.
Response Properties
Example Response
{
"email_id": "a1b2c3d4e5f6789012345678abcdef90",
"attachments": [
{
"attachment_id": 1,
"name": "invoice.pdf",
"file_extension": "pdf",
"size": 245760
},
{
"attachment_id": 2,
"name": "receipt.jpg",
"file_extension": "jpg",
"size": 102400
},
{
"attachment_id": 3,
"name": "document.docx",
"file_extension": "docx",
"size": 51200
}
],
"count": 3
}
Examples
JavaScript Example
const apiHost = 'http://localhost:8080';
const emailId = 'a1b2c3d4e5f6789012345678abcdef90';
async function getAttachments(emailId) {
try {
const response = await fetch(`${apiHost}/api/mail/${emailId}/attachments`);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
console.log(`Email ID: ${data.email_id}`);
console.log(`Total attachments: ${data.count}`);
console.log('\nAttachments:');
data.attachments.forEach(attachment => {
console.log(` ID: ${attachment.attachment_id}`);
console.log(` Name: ${attachment.name}`);
console.log(` Extension: ${attachment.file_extension}`);
console.log(` Size: ${attachment.size} bytes`);
console.log('---');
});
} catch (error) {
console.error('Error fetching attachments:', error);
}
}
getAttachments(emailId);
cURL Example
curl -X GET "http://localhost:8080/api/mail/a1b2c3d4e5f6789012345678abcdef90/attachments" \
-H "Accept: application/json"
Go Example
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
const apiHost = "http://localhost:8080"
type Attachment struct {
AttachmentID int `json:"attachment_id"`
Name string `json:"name"`
FileExtension string `json:"file_extension"`
Size int `json:"size"`
}
type AttachmentsResponse struct {
EmailID string `json:"email_id"`
Attachments []Attachment `json:"attachments"`
Count int `json:"count"`
}
func main() {
emailID := "a1b2c3d4e5f6789012345678abcdef90"
// Make GET request
resp, err := http.Get(fmt.Sprintf("%s/api/mail/%s/attachments", apiHost, emailID))
if err != nil {
panic(err)
}
defer resp.Body.Close()
// Read response body
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
// Parse JSON response
var result AttachmentsResponse
err = json.Unmarshal(body, &result)
if err != nil {
panic(err)
}
// Display results
fmt.Printf("Email ID: %s\n", result.EmailID)
fmt.Printf("Total attachments: %d\n\n", result.Count)
fmt.Println("Attachments:")
for _, attachment := range result.Attachments {
fmt.Printf(" ID: %d\n", attachment.AttachmentID)
fmt.Printf(" Name: %s\n", attachment.Name)
fmt.Printf(" Extension: %s\n", attachment.FileExtension)
fmt.Printf(" Size: %d bytes\n", attachment.Size)
fmt.Println("---")
}
}
Related Endpoints
/mail/{id}/attachment/{n}
Download a specific attachment file by its ID. Returns the binary file with appropriate headers.