Messages
Inspect captured emails
Interactions with messages
Get email message by ID.
Pass the API token in the Api-Token
Unique sandbox ID
4015Unique message ID
427Returns email message with its attributes.
Email message captured in a Sandbox. Body URLs are often under /api/testing_message_parts/... rather than nested under /api/accounts/.../messages/....
blacklists_report_info may contain only result or the full report. template_variables is set when the message was sent from a template.
Returns unauthorized error message. Check your credentials.
Returns forbidden error message. Check your permissions.
Returns not found error message
curl -X GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id} \
-H 'Authorization: Bearer YOUR_API_KEY'
{
"id": 2323,
"sandbox_id": 17002,
"subject": "Test email",
"sent_at": "2022-07-01T19:29:59.295Z",
"from_email": "john@mailtrap.io",
"from_name": "John",
"to_email": "mary@mailtrap.io",
"to_name": "Mary",
"email_size": 300,
"is_read": false,
"created_at": "2022-07-01T19:29:59.295Z",
"updated_at": "2022-07-01T19:29:59.295Z",
"template_id": 0,
"template_variables": null,
"html_body_size": 150,
"text_body_size": 100,
"human_size": "300 Bytes",
"html_path": "/api/accounts/16297/sandboxes/17002/messages/2323/body.html",
"txt_path": "/api/accounts/16297/sandboxes/17002/messages/2323/body.txt",
"raw_path": "/api/accounts/16297/sandboxes/17002/messages/2323/body.raw",
"download_path": "/api/accounts/16297/sandboxes/17002/messages/2323/body.eml",
"html_source_path": "/api/accounts/16297/sandboxes/17002/messages/2323/body.htmlsource",
"blacklists_report_info": {
"result": "success",
"domain": "example.com",
"ip": "23.215.0.138",
"report": []
},
"smtp_information": {
"ok": true,
"data": {
"mail_from_addr": "john@mailtrap.io",
"client_ip": "193.62.62.184",
"rcpt_to_addrs": [
"mary@mailtrap.io"
]
}
}
}Delete message from sandbox.
Pass the API token in the Api-Token
Unique sandbox ID
4015Unique message ID
427Returns attributes of the deleted message.
Returns unauthorized error message. Check your credentials.
Returns forbidden error message. Check your permissions.
Returns not found error message
curl -X DELETE https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id} \
-H 'Authorization: Bearer YOUR_API_KEY'
{
"id": 433,
"sandbox_id": 4338,
"subject": "Test email",
"sent_at": "2022-06-02T19:24:10.746Z",
"from_email": "john@mailtrap.io",
"from_name": "John",
"to_email": "mary@mailtrap.io",
"to_name": "Mary",
"email_size": 300,
"is_read": false,
"created_at": "2022-06-02T19:24:10.747Z",
"updated_at": "2022-06-02T19:24:10.747Z",
"html_body_size": 150,
"text_body_size": 100,
"human_size": "300 Bytes",
"html_path": "/api/accounts/3775/sandboxes/4338/messages/433/body.html",
"txt_path": "/api/accounts/3775/sandboxes/4338/messages/433/body.txt",
"raw_path": "/api/accounts/3775/sandboxes/4338/messages/433/body.raw",
"download_path": "/api/accounts/3775/sandboxes/4338/messages/433/body.eml",
"html_source_path": "/api/accounts/3775/sandboxes/4338/messages/433/body.htmlsource",
"blacklists_report_info": false,
"smtp_information": {
"ok": true,
"data": {
"mail_from_addr": "john@mailtrap.io",
"client_ip": "193.62.62.184"
}
}
}Update message attributes (right now only the is_read attribute is available for modification).
Pass the API token in the Api-Token
Unique sandbox ID
4015Unique message ID
427Returns attributes of the updated message.
Returns unauthorized error message. Check your credentials.
Returns forbidden error message. Check your permissions.
Returns not found error message
curl -X PATCH https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id} \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{"message": {"is_read": "true"}}'
{
"id": 427,
"sandbox_id": 4324,
"subject": "Test email",
"sent_at": "2022-06-02T19:24:08.941Z",
"from_email": "john@mailtrap.io",
"from_name": "John",
"to_email": "mary@mailtrap.io",
"to_name": "Mary",
"email_size": 300,
"is_read": false,
"created_at": "2022-06-02T19:24:08.942Z",
"updated_at": "2022-06-02T19:24:08.942Z",
"html_body_size": 150,
"text_body_size": 100,
"human_size": "300 Bytes",
"html_path": "/api/accounts/3761/sandboxes/4324/messages/427/body.html",
"txt_path": "/api/accounts/3761/sandboxes/4324/messages/427/body.txt",
"raw_path": "/api/accounts/3761/sandboxes/4324/messages/427/body.raw",
"download_path": "/api/accounts/3761/sandboxes/4324/messages/427/body.eml",
"html_source_path": "/api/accounts/3761/sandboxes/4324/messages/427/body.htmlsource",
"blacklists_report_info": false,
"smtp_information": {
"ok": true,
"data": {
"mail_from_addr": "john@mailtrap.io",
"client_ip": "193.62.62.184"
}
}
}Get all messages in the sandbox. The response contains up to 30 messages. Use last_id or page to retrieve more.
Pass the API token in the Api-Token
Unique sandbox ID
4015Search query string. Matches subject, to_email, and to_name.
welcomeIf specified, a page of records before last_id is returned. Overrides page if both are given.
123Page number for paginated results.
5lists messages
Email message captured in a Sandbox. Body URLs are often under /api/testing_message_parts/... rather than nested under /api/accounts/.../messages/....
blacklists_report_info may contain only result or the full report. template_variables is set when the message was sent from a template.
Returns unauthorized error message. Check your credentials.
Returns forbidden error message. Check your permissions.
curl -X GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages \
-H 'Authorization: Bearer YOUR_API_KEY'
[
{
"id": 92,
"sandbox_id": 342,
"subject": "Test email",
"sent_at": "2022-08-19T11:34:33.839Z",
"from_email": "per667son25@feeney.biz",
"from_name": "Ela Marks",
"to_email": "per688son26@donnelly.info",
"to_name": "Edmund Maggio",
"email_size": 300,
"is_read": false,
"created_at": "2022-08-19T11:34:33.841Z",
"updated_at": "2022-08-19T11:34:33.841Z",
"template_id": 0,
"template_variables": null,
"html_body_size": 150,
"text_body_size": 100,
"human_size": "300 Bytes",
"html_path": "/api/accounts/336/sandboxes/342/messages/92/body.html",
"txt_path": "/api/accounts/336/sandboxes/342/messages/92/body.txt",
"raw_path": "/api/accounts/336/sandboxes/342/messages/92/body.raw",
"download_path": "/api/accounts/336/sandboxes/342/messages/92/body.eml",
"html_source_path": "/api/accounts/336/sandboxes/342/messages/92/body.htmlsource",
"blacklists_report_info": {
"result": "pending"
},
"smtp_information": {
"ok": true,
"data": {
"mail_from_addr": "per667son25@feeney.biz",
"client_ip": "75.180.183.201",
"rcpt_to_addrs": [
"per688son26@donnelly.info"
]
}
}
}
]Forward message to an email address. The email address must be confirmed by the recipient in advance.
Pass the API token in the Api-Token
Unique sandbox ID
4015Unique message ID
427jack@mailtrap.ioReturns confirmation about forwarding.
Returns unauthorized error message. Check your credentials.
Returns forbidden error message. Check your permissions.
Returns not found error message
curl -X POST https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id}/forward \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{"email": "recipient@example.com"}'
{
"message": "Your email message has been successfully forwarded"
}Get a brief spam report by message ID.
Pass the API token in the Api-Token
Unique sandbox ID
4015Unique message ID
427Returns message spam analysis report.
Returns unauthorized error message. Check your credentials.
Returns forbidden error message. Check your permissions.
Returns not found error message
curl -X GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id}/spam_report \
-H 'Authorization: Bearer YOUR_API_KEY'
{
"report": {
"ResponseCode": 2,
"ResponseMessage": "Not spam",
"ResponseVersion": "1.2",
"Score": 1.2,
"Spam": false,
"Threshold": 5,
"Details": [
{
"Pts": 0,
"RuleName": "HTML_MESSAGE",
"Description": "BODY: HTML included in message"
}
]
}
}Get a brief HTML report by message ID.
Pass the API token in the Api-Token
Unique sandbox ID
4015Unique message ID
427Returns message HTML analysis report.
Returns unauthorized error message. Check your credentials.
Returns forbidden error message. Check your permissions.
Returns not found error message
curl -X GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id}/analyze \
-H 'Authorization: Bearer YOUR_API_KEY'
{
"report": {
"status": "success",
"errors": [
{
"error_line": 15,
"rule_name": "style",
"email_clients": {
"desktop": [
"Notes 6 / 7"
],
"mobile": [
"Gmail"
]
}
},
{
"error_line": 7,
"rule_name": "display",
"email_clients": {
"desktop": [
"AOL Desktop",
"IBM Notes 9",
"Outlook 2000–03",
"Outlook 2007–16",
"Outlook Express",
"Postbox",
"Windows 10 Mail",
"Windows Live Mail"
],
"mobile": [
"Android 4.2.2 Mail",
"Android 4.4.4 Mail",
"BlackBerry",
"Gmail Android app IMAP",
"Google Inbox Android app",
"Windows Phone 8 Mail",
"Yahoo! Mail Android app",
"Yahoo! Mail iOS app"
],
"web": [
"Yahoo! Mail"
]
}
}
]
}
}Get text email body, if it exists.
Pass the API token in the Api-Token
Unique sandbox ID
4015Unique message ID
427Returns message body in txt format.
Congrats for sending test email with Mailtrap! Inspect it using the tabs above and learn how this email can be improved. Now send your email using our fake SMTP server and integration of your choice! Good luck! Hope it works.Returns unauthorized error message. Check your credentials.
Returns forbidden error message. Check your permissions.
Returns not found error message
Returns conflict error message. Text body does not exist.
curl -X GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id}/body.txt \
-H 'Authorization: Bearer YOUR_API_KEY'
Congrats for sending test email with Mailtrap!
Inspect it using the tabs above and learn how this email can be improved.
Now send your email using our fake SMTP server and integration of your choice!
Good luck! Hope it works.
Get raw email body.
Pass the API token in the Api-Token
Unique sandbox ID
4015Unique message ID
427Returns raw message body.
From: Magic Elves <from@example.com> To: Mailtrap Inbox <to@example.com> Subject: You are awesome! Content-Type: multipart/alternative; boundary="boundary-string" --boundary-string Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Congrats for sending test email with Mailtrap! Inspect it using the tabs above and learn how this email can be improved. Now send your email using our fake SMTP server and integration of your choice! Good luck! Hope it works. --boundary-string Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline <!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body style="font-family: sans-serif;"> <div style="display: block; margin: auto; max-width: 600px;" class="main"> <h1 style="font-size: 18px; font-weight: bold; margin-top: 20px"> Congrats for sending test email with Mailtrap! </h1> <p>Inspect it using the tabs you see above and learn how this email can be improved.</p> <img alt="Inspect with Tabs" src="https://assets-examples.mailtrap.io/integration-examples/welcome.png" style="width: 100%;" > <p>Now send your email using our fake SMTP server and integration of your choice!</p> <p>Good luck! Hope it works.</p> </div> <!-- Example of invalid for email html/css, will be detected by Mailtrap: --> <style> .main { background-color: white; } a:hover { border-left-width: 1em; min-height: 2em; } </style> </body> </html> --boundary-string--Returns unauthorized error message. Check your credentials.
Returns forbidden error message. Check your permissions.
Returns not found error message
Returns conflict error message. Raw body does not exist.
curl -X GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id}/body.raw \
-H 'Authorization: Bearer YOUR_API_KEY'
From: Magic Elves <from@example.com>
To: Mailtrap Inbox <to@example.com>
Subject: You are awesome!
Content-Type: multipart/alternative; boundary="boundary-string"
--boundary-string
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
Congrats for sending test email with Mailtrap!
Inspect it using the tabs above and learn how this email can be improved.
Now send your email using our fake SMTP server and integration of your choice!
Good luck! Hope it works.
--boundary-string
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body style="font-family: sans-serif;">
<div style="display: block; margin: auto; max-width: 600px;" class="main">
<h1 style="font-size: 18px; font-weight: bold; margin-top: 20px">
Congrats for sending test email with Mailtrap!
</h1>
<p>Inspect it using the tabs you see above and learn how this email can be improved.</p>
<img
alt="Inspect with Tabs"
src="https://assets-examples.mailtrap.io/integration-examples/welcome.png"
style="width: 100%;"
>
<p>Now send your email using our fake SMTP server and integration of your choice!</p>
<p>Good luck! Hope it works.</p>
</div>
<!-- Example of invalid for email html/css, will be detected by Mailtrap: -->
<style>
.main { background-color: white; }
a:hover { border-left-width: 1em; min-height: 2em; }
</style>
</body>
</html>
--boundary-string--
Get HTML source of email.
Pass the API token in the Api-Token
Unique sandbox ID
4015Unique message ID
427Returns HTML source of a message.
<!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body style="font-family: sans-serif;"> <div style="display: block; margin: auto; max-width: 600px;" class="main"> <h1 style="font-size: 18px; font-weight: bold; margin-top: 20px">Congrats for sending test email with Mailtrap!</h1> <p>Inspect it using the tabs you see above and learn how this email can be improved. </p> <img alt="Inspect with Tabs" src="https://assets-examples.mailtrap.io/integration-examples/welcome.png" style="width: 100%;"> <p>Now send your email using our fake SMTP server and integration of your choice! </p> <p>Good luck! Hope it works.</p> </div> <!-- Example of invalid for email html/css, will be detected by Mailtrap: --> <style> .main { background-color: white; } a:hover { border-left-width: 1em; min-height: 2em; } </style> </body> </html>Returns unauthorized error message. Check your credentials.
Returns forbidden error message. Check your permissions.
Returns not found error message
Returns conflict error message. HTML source does not exist.
curl -X GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id}/body.htmlsource \
-H 'Authorization: Bearer YOUR_API_KEY'
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=UTF-8">
</head>
<body style="font-family:
sans-serif;">
<div style="display: block; margin: auto; max-width:
600px;" class="main">
<h1 style="font-size: 18px; font-weight: bold;
margin-top: 20px">Congrats for sending test email with Mailtrap!</h1>
<p>Inspect it using the tabs you see above and learn how this email
can be improved.
</p>
<img alt="Inspect with Tabs" src="https://assets-examples.mailtrap.io/integration-examples/welcome.png"
style="width: 100%;">
<p>Now send your email using our fake SMTP server
and integration of your choice!
</p>
<p>Good luck! Hope it works.</p>
</div>
<!-- Example of invalid for email html/css, will be detected
by Mailtrap: -->
<style> .main { background-color: white; } a:hover
{ border-left-width: 1em; min-height: 2em; }
</style>
</body>
</html>
Get formatted HTML email body. Not applicable for plain text emails.
Pass the API token in the Api-Token
Unique sandbox ID
4015Unique message ID
427Returns message body in html format.
<!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body style="font-family: sans-serif;"> <div style="display: block; margin: auto; max-width: 600px;" class="main"> <h1 style="font-size: 18px; font-weight: bold; margin-top: 20px">Congrats for sending test email with Mailtrap!</h1> <p>Inspect it using the tabs you see above and learn how this email can be improved. </p> <img alt="Inspect with Tabs" src="https://assets-examples.mailtrap.io/integration-examples/welcome.png" style="width: 100%;"> <p>Now send your email using our fake SMTP server and integration of your choice! </p> <p>Good luck! Hope it works.</p> </div> <!-- Example of invalid for email html/css, will be detected by Mailtrap: --> <style> .main { background-color: white; } a:hover { border-left-width: 1em; min-height: 2em; } </style> </body> </html>Returns unauthorized error message. Check your credentials.
Returns forbidden error message. Check your permissions.
Returns not found error message
Returns conflict error message. HTML source does not exist.
curl -X GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id}/body.html \
-H 'Authorization: Bearer YOUR_API_KEY'
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=UTF-8">
</head>
<body style="font-family:
sans-serif;">
<div style="display: block; margin: auto; max-width:
600px;" class="main">
<h1 style="font-size: 18px; font-weight: bold;
margin-top: 20px">Congrats for sending test email with Mailtrap!</h1>
<p>Inspect it using the tabs you see above and learn how this email
can be improved.
</p>
<img alt="Inspect with Tabs" src="https://assets-examples.mailtrap.io/integration-examples/welcome.png"
style="width: 100%;">
<p>Now send your email using our fake SMTP server
and integration of your choice!
</p>
<p>Good luck! Hope it works.</p>
</div>
<!-- Example of invalid for email html/css, will be detected
by Mailtrap: -->
<style> .main { background-color: white; } a:hover
{ border-left-width: 1em; min-height: 2em; }
</style>
</body>
</html>
Get email message in .eml format.
Pass the API token in the Api-Token
Unique sandbox ID
4015Unique message ID
427Returns .eml of the message.
From: Magic Elves <from@example.com> To: Mailtrap Inbox <to@example.com> Subject: You are awesome! Content-Type: multipart/alternative; boundary="boundary-string" --boundary-string Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Congrats for sending test email with Mailtrap! Inspect it using the tabs above and learn how this email can be improved. Now send your email using our fake SMTP server and integration of your choice! Good luck! Hope it works. --boundary-string Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline <!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body style="font-family: sans-serif;"> <div style="display: block; margin: auto; max-width: 600px;" class="main"> <h1 style="font-size: 18px; font-weight: bold; margin-top: 20px"> Congrats for sending test email with Mailtrap! </h1> <p>Inspect it using the tabs you see above and learn how this email can be improved.</p> <img alt="Inspect with Tabs" src="https://assets-examples.mailtrap.io/integration-examples/welcome.png" style="width: 100%;" > <p>Now send your email using our fake SMTP server and integration of your choice!</p> <p>Good luck! Hope it works.</p> </div> <!-- Example of invalid for email html/css, will be detected by Mailtrap: --> <style> .main { background-color: white; } a:hover { border-left-width: 1em; min-height: 2em; } </style> </body> </html> --boundary-string--Returns unauthorized error message. Check your credentials.
Returns forbidden error message. Check your permissions.
Returns not found error message
Returns conflict error message. .eml body does not exist.
curl -X GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id}/body.eml \
-H 'Authorization: Bearer YOUR_API_KEY'
From: Magic Elves <from@example.com>
To: Mailtrap Inbox <to@example.com>
Subject: You are awesome!
Content-Type: multipart/alternative; boundary="boundary-string"
--boundary-string
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
Congrats for sending test email with Mailtrap!
Inspect it using the tabs above and learn how this email can be improved.
Now send your email using our fake SMTP server and integration of your choice!
Good luck! Hope it works.
--boundary-string
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body style="font-family: sans-serif;">
<div style="display: block; margin: auto; max-width: 600px;" class="main">
<h1 style="font-size: 18px; font-weight: bold; margin-top: 20px">
Congrats for sending test email with Mailtrap!
</h1>
<p>Inspect it using the tabs you see above and learn how this email can be improved.</p>
<img
alt="Inspect with Tabs"
src="https://assets-examples.mailtrap.io/integration-examples/welcome.png"
style="width: 100%;"
>
<p>Now send your email using our fake SMTP server and integration of your choice!</p>
<p>Good luck! Hope it works.</p>
</div>
<!-- Example of invalid for email html/css, will be detected by Mailtrap: -->
<style>
.main { background-color: white; }
a:hover { border-left-width: 1em; min-height: 2em; }
</style>
</body>
</html>
--boundary-string--
Get mail headers of a message
Pass the API token in the Api-Token
Unique sandbox ID
4015Unique message ID
427Returns mail headers of the message
An object containing key/value pairs of header names and value. The key/value pairs must be strings.
Returns unauthorized error message. Check your credentials.
Returns forbidden error message. Check your permissions.
Returns not found error message
curl -X GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id}/mail_headers \
-H 'Authorization: Bearer YOUR_API_KEY'
{
"headers": {
"bcc": "john_doe@example.com",
"cc": "john_doe@example.com",
"from": "john_doe@example.com",
"to": "john_doe@example.com",
"subject": "Your Example Order Confirmation"
}
}Last updated
Was this helpful?

