> For the complete documentation index, see [llms.txt](https://docs.mailtrap.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mailtrap.io/developers/email-sandbox/messages/get-messages.md).

# Get messages

Get all messages in the sandbox. The response contains up to 30 messages. Use `last_id` or `page` to retrieve more.

```json
{"openapi":"3.1.0","info":{"title":"Email Sandbox","version":"2.0.0"},"tags":[{"name":"Messages","description":"Interactions with messages"}],"servers":[{"description":"Mailtrap API","url":"https://mailtrap.io"}],"security":[{"HeaderAuth":[]},{"BearerAuth":[]}],"components":{"securitySchemes":{"HeaderAuth":{"type":"apiKey","description":"Pass the API token in the Api-Token","in":"header","name":"Api-Token"},"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"JWT"}},"schemas":{"SandboxMessage":{"title":"Sandbox message","type":"object","description":"Email message captured in a Sandbox. Body URLs are often under `/api/testing_message_parts/...` rather than nested under `/api/accounts/.../messages/...`.\n`blacklists_report_info` may contain only `result` or the full report. `template_variables` is set when the message was sent from a template.\n","properties":{"id":{"type":"integer"},"sandbox_id":{"type":"integer"},"subject":{"type":"string"},"sent_at":{"type":"string"},"from_email":{"type":"string"},"from_name":{"type":"string"},"to_email":{"type":"string"},"to_name":{"type":"string"},"email_size":{"type":"integer"},"is_read":{"type":"boolean"},"created_at":{"type":"string"},"updated_at":{"type":"string"},"template_id":{"type":"integer"},"template_variables":{"type":"object","nullable":true,"additionalProperties":true},"html_body_size":{"type":"integer"},"text_body_size":{"type":"integer"},"human_size":{"type":"string"},"html_path":{"type":"string"},"txt_path":{"type":"string"},"raw_path":{"type":"string"},"download_path":{"type":"string"},"html_source_path":{"type":"string"},"blacklists_report_info":{"type":"object","properties":{"result":{"type":"string","enum":["success","pending","error"]},"domain":{"type":"string"},"ip":{"type":"string"},"report":{"type":"array","items":{"type":"object","properties":{"name":{"type":"string"},"url":{"type":"string"},"in_black_list":{"type":"boolean"}}}}}},"smtp_information":{"type":"object","properties":{"ok":{"type":"boolean"},"data":{"type":"object","properties":{"mail_from_addr":{"type":"string"},"client_ip":{"type":"string"},"rcpt_to_addrs":{"type":"array","items":{"type":"string"}}}}}}}},"UnauthenticatedResponse":{"title":"UnauthenticatedResponse","type":"object","properties":{"error":{"type":"string","description":"Error message"}}}},"responses":{"UNAUTHENTICATED":{"description":"Returns unauthorized error message. Check your credentials.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthenticatedResponse"}}}}}},"paths":{"/api/sandboxes/{sandbox_id}/messages":{"get":{"summary":"Get messages","description":"Get all messages in the sandbox. The response contains up to 30 messages. Use `last_id` or `page` to retrieve more.","tags":["Messages"],"responses":{"200":{"description":"lists messages","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/SandboxMessage"}}}}},"401":{"$ref":"#/components/responses/UNAUTHENTICATED"},"403":{"description":"Returns forbidden error message. Check your permissions.","content":{"application/json":{"schema":{"type":"object","properties":{"errors":{"type":"string"}}}}}}},"operationId":"getSandboxEmailMessage","parameters":[{"schema":{"type":"string"},"in":"query","name":"search","description":"Search query string. Matches `subject`, `to_email`,  and `to_name`."},{"schema":{"type":"number","minimum":1},"in":"query","name":"last_id","description":"If specified, a page of records before `last_id` is  returned. Overrides `page` if both are given."},{"schema":{"type":"number","minimum":1},"in":"query","name":"page","description":"Page number for paginated results."}]}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.mailtrap.io/developers/email-sandbox/messages/get-messages.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
