Mailtrap API is based on the REST principles. The following documentation covers core resources that are used to manipulate the main entities. To start using the Mailtrap API, only a Mailtrap account is required. You have to be authenticated and call the simple HTTPS request on the URL specified below. Please read these basic instructions before you start working with the API.
Mailtrap API is based on the REST principles. The following documentation covers core resources that are used to manipulate the main entities. To start using the Mailtrap API, only a Mailtrap account is required. You have to be authenticated and call the simple HTTPS request on the URL specified below. Please read these basic instructions before you start working with the API.
There are several ways to send authenticated HTTP requests:
{api_token}, where {api_token} is your API token#{token}, where {api_token} is your API token (more info: Token Access Authentication)You can manage your API token on the API Tokens page. API token does not have an expiration date, you may reset it manually.
Allowed requests and common responses
Here is the description of common server responses
All requests must be sent over HTTPS protocol.
Authentication
No API Key applied
API Key (Api-Token)
Pass the API token in the Api-Token header. Read more about API tokens Send Api-Token in header
EMAIL API
Pordution email sending
API server: send api.Mailtrap.io
EMAILS
Send email
POST /api/send
REQUEST
REQUEST BODY application/json
"to": [
{
"email": "john_doe@example.com",
"name": "John Doe"
}
],
"cc": [
{
"email": "jane_doe@example.com",
"name": "Jane Doe"
}
],
"bcc": [
{
"email": "james_doe@example.com",
"name": "Jim Doe"
}
],
"from": {
"email": "sales@example.com",
"name": "Example Sales Team"
},
"subject": "Your Example Order Confirmation",
"html": "
Congratulations on your order no. 1234. "category": "cake", "custom_variables": { "variable1": "value1", "variable2": "value2" }, "headers": { "header1": "value1" }
from*: {
email: string
name: string
}
to*: [{
Min Items: 1 Max Items: 1000
email: string
name: string
}]
cc: [{
Max Items: 1000
email: string
name: string
}]
bcc: [{
An array of recipients who will receive a blind carbon copy of your email. Each object in this array must contain the recipient's email address. Each object in the array may optionally contain the recipient's name.
Max Items: 1000
email: string
name: string
}]
subject*: string
The global or 'message level' subject of your email. This may be overridden by subject lines set in personalizations.Constraints: Min 1 chars
text*: string
Text version of the body of the email. Can be used along with html to create a fallback for non-html clients. Required in the absence of html.Constraints: Min 1 chars
html*: string
HTML version of the body of the email. Can be used along with text to create a fallback for non-html clients. Required in the absence of text.Constraints: Min 1 chars
attachments: [{
An array of objects where you can specify any attachments you want to include.
content*: string
The Base64 encoded content of the attachment.Constraints: Min 1 chars
type: string
The MIME type of the content you are attaching (e.g., “text/plain” or “text/html”).Constraints: Min 1 chars
filename*: string
The attachment's filename.
disposition: enum
The attachment's content-disposition, specifying how you would like the attachment to be displayed. For example, “inline” results in the attached file are displayed automatically within the message while “attachment” results in the attached file require some action to be taken before it is displayed, such as opening or downloading the file.Default: attachment Allowed: inline┃attachment
content_id: string
The attachment's content ID. This is used when the disposition is set to “inline” and the attachment is an image, allowing the file to be displayed within the body of your email.
}]
headers: {
An object containing key/value pairs of header names and the value to substitute for them. The key/value pairs must be strings. You must ensure these are properly encoded if they contain unicode characters. These headers cannot be one of the reserved headers.
API Server https://send.api.mailtrap.io
Authentication Required (None Applied)
Response
Success. Message has been delivered.
"to": [
{
"email": "john_doe@example.com",
"name": "John Doe"
}
],
"cc": [
{
"email": "jane_doe@example.com",
"name": "Jane Doe"
}
],
"bcc": [
{
"email": "james_doe@example.com",
"name": "Jim Doe"
}
],
"from": {
"email": "sales@example.com",
"name": "Example Sales Team"
},
"subject": "Your Example Order Confirmation",
"html": "
Congratulations on your order no. 1234. "category": "cake", "custom_variables": { "variable1": "value1", "variable2": "value2" }, "headers": { "header1": "value1" }
from*: {
email: string
name: string
}
to*: [{
Min Items: 1 Max Items: 1000
email: string
name: string
}]
cc: [{
Max Items: 1000
email: string
name: string
}]
bcc: [{
An array of recipients who will receive a blind carbon copy of your email. Each object in this array must contain the recipient's email address. Each object in the array may optionally contain the recipient's name.
Max Items: 1000
email: string
name: string
}]
subject*: string
The global or 'message level' subject of your email. This may be overridden by subject lines set in personalizations.Constraints: Min 1 chars
text*: string
Text version of the body of the email. Can be used along with html to create a fallback for non-html clients. Required in the absence of html.Constraints: Min 1 chars
html*: string
HTML version of the body of the email. Can be used along with text to create a fallback for non-html clients. Required in the absence of text.Constraints: Min 1 chars
attachments: [{
An array of objects where you can specify any attachments you want to include.
content*: string
The Base64 encoded content of the attachment.Constraints: Min 1 chars
type: string
The MIME type of the content you are attaching (e.g., “text/plain” or “text/html”).Constraints: Min 1 chars
filename*: string
The attachment's filename.
disposition: enum
The attachment's content-disposition, specifying how you would like the attachment to be displayed. For example, “inline” results in the attached file are displayed automatically within the message while “attachment” results in the attached file require some action to be taken before it is displayed, such as opening or downloading the file.Default: attachment Allowed: inline┃attachment
content_id: string
The attachment's content ID. This is used when the disposition is set to “inline” and the attachment is an image, allowing the file to be displayed within the body of your email.
}]
headers: {
An object containing key/value pairs of header names and the value to substitute for them. The key/value pairs must be strings. You must ensure these are properly encoded if they contain unicode characters. These headers cannot be one of the reserved headers.
WEBHOOKS
Receive events
Read more about Webhooks in our Knowledge Base.
Request
REQUEST BODY application/json
Mail events that user is subscribed to
"to": [
{
"email": "john_doe@example.com",
"name": "John Doe"
}
],
"cc": [
{
"email": "jane_doe@example.com",
"name": "Jane Doe"
}
],
"bcc": [
{
"email": "james_doe@example.com",
"name": "Jim Doe"
}
],
"from": {
"email": "sales@example.com",
"name": "Example Sales Team"
},
"subject": "Your Example Order Confirmation",
"html": "
Congratulations on your order no. 1234. "category": "cake", "custom_variables": { "variable1": "value1", "variable2": "value2" }, "headers": { "header1": "value1" }
from*: {
email: string
name: string
}
to*: [{
Min Items: 1 Max Items: 1000
email: string
name: string
}]
cc: [{
Max Items: 1000
email: string
name: string
}]
bcc: [{
An array of recipients who will receive a blind carbon copy of your email. Each object in this array must contain the recipient's email address. Each object in the array may optionally contain the recipient's name.
Max Items: 1000
email: string
name: string
}]
subject*: string
The global or 'message level' subject of your email. This may be overridden by subject lines set in personalizations.Constraints: Min 1 chars
text*: string
Text version of the body of the email. Can be used along with html to create a fallback for non-html clients. Required in the absence of html.Constraints: Min 1 chars
html*: string
HTML version of the body of the email. Can be used along with text to create a fallback for non-html clients. Required in the absence of text.Constraints: Min 1 chars
attachments: [{
An array of objects where you can specify any attachments you want to include.
content*: string
The Base64 encoded content of the attachment.Constraints: Min 1 chars
type: string
The MIME type of the content you are attaching (e.g., “text/plain” or “text/html”).Constraints: Min 1 chars
filename*: string
The attachment's filename.
disposition: enum
The attachment's content-disposition, specifying how you would like the attachment to be displayed. For example, “inline” results in the attached file are displayed automatically within the message while “attachment” results in the attached file require some action to be taken before it is displayed, such as opening or downloading the file.Default: attachment Allowed: inline┃attachment
content_id: string
The attachment's content ID. This is used when the disposition is set to “inline” and the attachment is an image, allowing the file to be displayed within the body of your email.
}]
headers: {
An object containing key/value pairs of header names and the value to substitute for them. The key/value pairs must be strings. You must ensure these are properly encoded if they contain unicode characters. These headers cannot be one of the reserved headers.
SandBOX
Test emails for staging.
API Server:mailtrap.io
ACCOUNTS
Get all accounts
"to": [
{
"email": "john_doe@example.com",
"name": "John Doe"
}
],
"cc": [
{
"email": "jane_doe@example.com",
"name": "Jane Doe"
}
],
"bcc": [
{
"email": "james_doe@example.com",
"name": "Jim Doe"
}
],
"from": {
"email": "sales@example.com",
"name": "Example Sales Team"
},
"subject": "Your Example Order Confirmation",
"html": "
Congratulations on your order no. 1234. "category": "cake", "custom_variables": { "variable1": "value1", "variable2": "value2" }, "headers": { "header1": "value1" }
from*: {
email: string
name: string
}
to*: [{
Min Items: 1 Max Items: 1000
email: string
name: string
}]
cc: [{
Max Items: 1000
email: string
name: string
}]
bcc: [{
An array of recipients who will receive a blind carbon copy of your email. Each object in this array must contain the recipient's email address. Each object in the array may optionally contain the recipient's name.
Max Items: 1000
email: string
name: string
}]
subject*: string
The global or 'message level' subject of your email. This may be overridden by subject lines set in personalizations.Constraints: Min 1 chars
text*: string
Text version of the body of the email. Can be used along with html to create a fallback for non-html clients. Required in the absence of html.Constraints: Min 1 chars
html*: string
HTML version of the body of the email. Can be used along with text to create a fallback for non-html clients. Required in the absence of text.Constraints: Min 1 chars
attachments: [{
An array of objects where you can specify any attachments you want to include.
content*: string
The Base64 encoded content of the attachment.Constraints: Min 1 chars
type: string
The MIME type of the content you are attaching (e.g., “text/plain” or “text/html”).Constraints: Min 1 chars
filename*: string
The attachment's filename.
disposition: enum
The attachment's content-disposition, specifying how you would like the attachment to be displayed. For example, “inline” results in the attached file are displayed automatically within the message while “attachment” results in the attached file require some action to be taken before it is displayed, such as opening or downloading the file.Default: attachment Allowed: inline┃attachment
content_id: string
The attachment's content ID. This is used when the disposition is set to “inline” and the attachment is an image, allowing the file to be displayed within the body of your email.
}]
headers: {
An object containing key/value pairs of header names and the value to substitute for them. The key/value pairs must be strings. You must ensure these are properly encoded if they contain unicode characters. These headers cannot be one of the reserved headers.
Mailtrap is a test mail server solution that allows testing email notifications without sending them to the real users of your application. Not only does Mailtrap work as a powerful email test tool, it also lets you view your dummy emails online, forward them to your regular mailbox, share with the team and more! Mailtrap is a mail server test tool built by Railsware Products, Inc., a premium software development consulting company.
© Masai School, Inc.