> 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.md).

# Messages

Interactions with messages

## Show email message

> Get email message by ID.

```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"}}},"NotFoundResponse":{"title":"NotFoundResponse","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"}}}},"NOT_FOUND":{"description":"Returns not found error message","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NotFoundResponse"}}}}}},"paths":{"/api/sandboxes/{sandbox_id}/messages/{message_id}":{"get":{"summary":"Show email message","description":"Get email message by ID.","tags":["Messages"],"responses":{"200":{"description":"Returns email message with its attributes.","content":{"application/json":{"schema":{"$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"}}}}}},"404":{"$ref":"#/components/responses/NOT_FOUND"}},"operationId":"showSandboxEmailMessage"}}}}
```

## Delete message

> Delete message from sandbox.

```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"}},"responses":{"UNAUTHENTICATED":{"description":"Returns unauthorized error message. Check your credentials.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthenticatedResponse"}}}},"PERMISSION_DENIED":{"description":"Returns forbidden error message. Check your permissions.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PermissionsDeniedResponse"}}}},"NOT_FOUND":{"description":"Returns not found error message","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NotFoundResponse"}}}}},"schemas":{"UnauthenticatedResponse":{"title":"UnauthenticatedResponse","type":"object","properties":{"error":{"type":"string","description":"Error message"}}},"PermissionsDeniedResponse":{"title":"PermissionsDeniedResponse","type":"object","properties":{"errors":{"type":"string","description":"Error message"}}},"NotFoundResponse":{"title":"NotFoundResponse","type":"object","properties":{"error":{"type":"string","description":"Error message"}}}}},"paths":{"/api/sandboxes/{sandbox_id}/messages/{message_id}":{"delete":{"summary":"Delete message","description":"Delete message from sandbox.","tags":["Messages"],"responses":{"200":{"description":"Returns attributes of the deleted message.","content":{"application/json":{"schema":{"type":"object","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"},"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":"boolean"},"smtp_information":{"type":"object","properties":{"ok":{"type":"boolean"},"data":{"type":"object","properties":{"mail_from_addr":{"type":"string"},"client_ip":{"type":"string"}}}}}}}}}},"401":{"$ref":"#/components/responses/UNAUTHENTICATED"},"403":{"$ref":"#/components/responses/PERMISSION_DENIED"},"404":{"$ref":"#/components/responses/NOT_FOUND"}},"operationId":"deleteSandboxEmailMessage"}}}}
```

## Update message

> Update message attributes (right now only the \*\*is\_read\*\* attribute is available for modification).

```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"}},"responses":{"UNAUTHENTICATED":{"description":"Returns unauthorized error message. Check your credentials.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthenticatedResponse"}}}},"NOT_FOUND":{"description":"Returns not found error message","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NotFoundResponse"}}}}},"schemas":{"UnauthenticatedResponse":{"title":"UnauthenticatedResponse","type":"object","properties":{"error":{"type":"string","description":"Error message"}}},"NotFoundResponse":{"title":"NotFoundResponse","type":"object","properties":{"error":{"type":"string","description":"Error message"}}}}},"paths":{"/api/sandboxes/{sandbox_id}/messages/{message_id}":{"patch":{"summary":"Update message","description":"Update message attributes (right now only the **is_read** attribute is available for modification).","tags":["Messages"],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"message":{"type":"object","properties":{"is_read":{"type":"string"}}}}}}}},"responses":{"200":{"description":"Returns attributes of the updated message.","content":{"application/json":{"schema":{"type":"object","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"},"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":"boolean"},"smtp_information":{"type":"object","properties":{"ok":{"type":"boolean"},"data":{"type":"object","properties":{"mail_from_addr":{"type":"string"},"client_ip":{"type":"string"}}}}}}}}}},"401":{"$ref":"#/components/responses/UNAUTHENTICATED"},"403":{"description":"Returns forbidden error message. Check your permissions.","content":{"application/json":{"schema":{"type":"object","properties":{"errors":{"type":"string"}}}}}},"404":{"$ref":"#/components/responses/NOT_FOUND"}},"operationId":"updateSandboxEmailMessage"}}}}
```

## 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."}]}}}}
```

## Forward message

> Forward message to an email address. The email address must be confirmed by the recipient in advance.

```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"}},"responses":{"UNAUTHENTICATED":{"description":"Returns unauthorized error message. Check your credentials.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthenticatedResponse"}}}},"NOT_FOUND":{"description":"Returns not found error message","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NotFoundResponse"}}}}},"schemas":{"UnauthenticatedResponse":{"title":"UnauthenticatedResponse","type":"object","properties":{"error":{"type":"string","description":"Error message"}}},"NotFoundResponse":{"title":"NotFoundResponse","type":"object","properties":{"error":{"type":"string","description":"Error message"}}}}},"paths":{"/api/sandboxes/{sandbox_id}/messages/{message_id}/forward":{"post":{"summary":"Forward message","description":"Forward message to an email address. The email address must be confirmed by the recipient in advance.","tags":["Messages"],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"email":{"type":"string"}}}}}},"responses":{"200":{"description":"Returns confirmation about forwarding.","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"type":"string"}}}}}},"401":{"$ref":"#/components/responses/UNAUTHENTICATED"},"403":{"description":"Returns forbidden error message. Check your permissions.","content":{"application/json":{"schema":{"type":"object","properties":{"errors":{"type":"string"}}}}}},"404":{"$ref":"#/components/responses/NOT_FOUND"}},"operationId":"forwardSandboxEmailMessage"}}}}
```

## Get message spam score

> Get a brief spam report by message ID.

```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"}},"responses":{"UNAUTHENTICATED":{"description":"Returns unauthorized error message. Check your credentials.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthenticatedResponse"}}}},"NOT_FOUND":{"description":"Returns not found error message","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NotFoundResponse"}}}}},"schemas":{"UnauthenticatedResponse":{"title":"UnauthenticatedResponse","type":"object","properties":{"error":{"type":"string","description":"Error message"}}},"NotFoundResponse":{"title":"NotFoundResponse","type":"object","properties":{"error":{"type":"string","description":"Error message"}}}}},"paths":{"/api/sandboxes/{sandbox_id}/messages/{message_id}/spam_report":{"get":{"summary":"Get message spam score","description":"Get a brief spam report by message ID.","tags":["Messages"],"responses":{"200":{"description":"Returns message spam analysis report.","content":{"application/json":{"schema":{"type":"object","properties":{"report":{"type":"object","properties":{"ResponseCode":{"type":"integer"},"ResponseMessage":{"type":"string"},"ResponseVersion":{"type":"string"},"Score":{"type":"number","format":"float"},"Spam":{"type":"boolean"},"Threshold":{"type":"number","format":"float"},"Details":{"type":"array","items":{"type":"object","nullable":true,"properties":{"Pts":{"type":"number","format":"float"},"RuleName":{"type":"string"},"Description":{"type":"string"}}}}}}}}}}},"401":{"$ref":"#/components/responses/UNAUTHENTICATED"},"403":{"description":"Returns forbidden error message. Check your permissions.","content":{"application/json":{"schema":{"type":"object","properties":{"errors":{"type":"string"}}}}}},"404":{"$ref":"#/components/responses/NOT_FOUND"}},"operationId":"getSandboxEmailMessageSpamReport"}}}}
```

## Get message HTML analysis

> Get a brief HTML report by message ID.

```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"}},"responses":{"UNAUTHENTICATED":{"description":"Returns unauthorized error message. Check your credentials.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthenticatedResponse"}}}},"NOT_FOUND":{"description":"Returns not found error message","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NotFoundResponse"}}}}},"schemas":{"UnauthenticatedResponse":{"title":"UnauthenticatedResponse","type":"object","properties":{"error":{"type":"string","description":"Error message"}}},"NotFoundResponse":{"title":"NotFoundResponse","type":"object","properties":{"error":{"type":"string","description":"Error message"}}}}},"paths":{"/api/sandboxes/{sandbox_id}/messages/{message_id}/analyze":{"get":{"summary":"Get message HTML analysis","description":"Get a brief HTML report by message ID.","tags":["Messages"],"responses":{"200":{"description":"Returns message HTML analysis report.","content":{"application/json":{"schema":{"type":"object","properties":{"report":{"type":"object","properties":{"success":{"type":"string"},"errors":{"type":"array","items":{"type":"object","nullable":true,"properties":{"error_line":{"type":"number"},"rule_name":{"type":"string"},"email_clients":{"type":"object","properties":{"desktop":{"type":"array","items":{"type":"string"}},"mobile":{"type":"array","items":{"type":"string"}},"web":{"type":"array","items":{"type":"string"}}}}}}}}}}}}}},"401":{"$ref":"#/components/responses/UNAUTHENTICATED"},"403":{"description":"Returns forbidden error message. Check your permissions.","content":{"application/json":{"schema":{"type":"object","properties":{"errors":{"type":"string"}}}}}},"404":{"$ref":"#/components/responses/NOT_FOUND"}},"operationId":"getSandboxEmailMessageHTMLAnalysis"}}}}
```

## Get text message

> Get text email body, if it exists.

```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"}},"responses":{"NOT_FOUND":{"description":"Returns not found error message","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NotFoundResponse"}}}}},"schemas":{"NotFoundResponse":{"title":"NotFoundResponse","type":"object","properties":{"error":{"type":"string","description":"Error message"}}}}},"paths":{"/api/sandboxes/{sandbox_id}/messages/{message_id}/body.txt":{"get":{"summary":"Get text message","description":"Get text email body, if it exists.","tags":["Messages"],"responses":{"200":{"description":"Returns message body in txt format.","content":{"text/plain":{"schema":{"type":"string"}}}},"401":{"description":"Returns unauthorized error message. Check your credentials.","content":{"text/plain":{"schema":{"type":"string"}}}},"403":{"description":"Returns forbidden error message. Check your permissions.","content":{"text/plain":{"schema":{"type":"string"}}}},"404":{"$ref":"#/components/responses/NOT_FOUND"},"409":{"description":"Returns conflict error message. Text body does not exist.","content":{"text/plain":{"schema":{"type":"string"}}}}},"operationId":"getSandboxEmailMessageBodyAsTxt"}}}}
```

## Get raw message

> Get raw email body.

```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"}},"responses":{"NOT_FOUND":{"description":"Returns not found error message","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NotFoundResponse"}}}}},"schemas":{"NotFoundResponse":{"title":"NotFoundResponse","type":"object","properties":{"error":{"type":"string","description":"Error message"}}}}},"paths":{"/api/sandboxes/{sandbox_id}/messages/{message_id}/body.raw":{"get":{"summary":"Get raw message","description":"Get raw email body.","tags":["Messages"],"responses":{"200":{"description":"Returns raw message body.","content":{"text/plain":{"schema":{"type":"string"}}}},"401":{"description":"Returns unauthorized error message. Check your credentials.","content":{"text/plain":{"schema":{"type":"string"}}}},"403":{"description":"Returns forbidden error message. Check your permissions.","content":{"text/plain":{"schema":{"type":"string"}}}},"404":{"$ref":"#/components/responses/NOT_FOUND"},"409":{"description":"Returns conflict error message. Raw body does not exist.","content":{"text/plain":{"schema":{"type":"string"}}}}},"operationId":"getSandboxEmailMessageBodyAsRaw"}}}}
```

## Get message source

> Get HTML source of email.

```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"}},"responses":{"NOT_FOUND":{"description":"Returns not found error message","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NotFoundResponse"}}}}},"schemas":{"NotFoundResponse":{"title":"NotFoundResponse","type":"object","properties":{"error":{"type":"string","description":"Error message"}}}}},"paths":{"/api/sandboxes/{sandbox_id}/messages/{message_id}/body.htmlsource":{"get":{"summary":"Get message source","description":"Get HTML source of email.","tags":["Messages"],"responses":{"200":{"description":"Returns HTML source of a message.","content":{"text/html":{"schema":{"type":"string"}}}},"401":{"description":"Returns unauthorized error message. Check your credentials.","content":{"text/plain":{"schema":{"type":"string"}}}},"403":{"description":"Returns forbidden error message. Check your permissions.","content":{"text/plain":{"schema":{"type":"string"}}}},"404":{"$ref":"#/components/responses/NOT_FOUND"},"409":{"description":"Returns conflict error message. HTML source does not exist.","content":{"text/plain":{"schema":{"type":"string"}}}}},"operationId":"getSandboxEmailMessageBodyAsHtmlSource"}}}}
```

## Get HTML message

> Get formatted HTML email body. Not applicable for plain text emails.

```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"}},"responses":{"UNAUTHENTICATED":{"description":"Returns unauthorized error message. Check your credentials.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthenticatedResponse"}}}},"NOT_FOUND":{"description":"Returns not found error message","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NotFoundResponse"}}}}},"schemas":{"UnauthenticatedResponse":{"title":"UnauthenticatedResponse","type":"object","properties":{"error":{"type":"string","description":"Error message"}}},"NotFoundResponse":{"title":"NotFoundResponse","type":"object","properties":{"error":{"type":"string","description":"Error message"}}}}},"paths":{"/api/sandboxes/{sandbox_id}/messages/{message_id}/body.html":{"get":{"summary":"Get HTML message","description":"Get formatted HTML email body. Not applicable for plain text emails.","tags":["Messages"],"responses":{"200":{"description":"Returns message body in html format.","content":{"text/html":{"schema":{"type":"string"}}}},"401":{"$ref":"#/components/responses/UNAUTHENTICATED"},"403":{"description":"Returns forbidden error message. Check your permissions.","content":{"application/json":{"schema":{"type":"object","properties":{"errors":{"type":"string"}}}}}},"404":{"$ref":"#/components/responses/NOT_FOUND"},"409":{"description":"Returns conflict error message. HTML source does not exist.","content":{"text/plain":{"schema":{"type":"string"}}}}},"operationId":"getSandboxEmailMessageBodyAsHtml"}}}}
```

## Get message as .eml

> Get email message in .eml format.

```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"}},"responses":{"NOT_FOUND":{"description":"Returns not found error message","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NotFoundResponse"}}}}},"schemas":{"NotFoundResponse":{"title":"NotFoundResponse","type":"object","properties":{"error":{"type":"string","description":"Error message"}}}}},"paths":{"/api/sandboxes/{sandbox_id}/messages/{message_id}/body.eml":{"get":{"summary":"Get message as .eml","description":"Get email message in .eml format.","tags":["Messages"],"responses":{"200":{"description":"Returns .eml of the message.","content":{"message/rfc822":{"schema":{"type":"string","format":"binary"}}}},"401":{"description":"Returns unauthorized error message. Check your credentials.","content":{"text/plain":{"schema":{"type":"string"}}}},"403":{"description":"Returns forbidden error message. Check your permissions.","content":{"text/plain":{"schema":{"type":"string"}}}},"404":{"$ref":"#/components/responses/NOT_FOUND"},"409":{"description":"Returns conflict error message. .eml body does not exist.","content":{"text/plain":{"schema":{"type":"string"}}}}},"operationId":"getSandboxEmailMessageBodyAsEml"}}}}
```

## Get mail headers

> Get mail headers of a message

```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"}},"responses":{"UNAUTHENTICATED":{"description":"Returns unauthorized error message. Check your credentials.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/UnauthenticatedResponse"}}}},"PERMISSION_DENIED":{"description":"Returns forbidden error message. Check your permissions.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PermissionsDeniedResponse"}}}},"NOT_FOUND":{"description":"Returns not found error message","content":{"application/json":{"schema":{"$ref":"#/components/schemas/NotFoundResponse"}}}}},"schemas":{"UnauthenticatedResponse":{"title":"UnauthenticatedResponse","type":"object","properties":{"error":{"type":"string","description":"Error message"}}},"PermissionsDeniedResponse":{"title":"PermissionsDeniedResponse","type":"object","properties":{"errors":{"type":"string","description":"Error message"}}},"NotFoundResponse":{"title":"NotFoundResponse","type":"object","properties":{"error":{"type":"string","description":"Error message"}}}}},"paths":{"/api/sandboxes/{sandbox_id}/messages/{message_id}/mail_headers":{"get":{"summary":"Get mail headers","description":"Get mail headers of a message","tags":["Messages"],"responses":{"200":{"description":"Returns mail headers of the message","content":{"application/json":{"schema":{"type":"object","properties":{"headers":{"type":"object","description":"An object containing key/value pairs of header names and value. The key/value pairs must be strings."}}}}}},"401":{"$ref":"#/components/responses/UNAUTHENTICATED"},"403":{"$ref":"#/components/responses/PERMISSION_DENIED"},"404":{"$ref":"#/components/responses/NOT_FOUND"}},"operationId":"getMailHeadersOfEmailMessage"}}}}
```


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
