Overview
The Mailosaur API lets you test email using a simple REST API. You can make the API calls yourself, however because email and SMS messages can take time to arrive, we highly recommend using one of our official clients.
Authentication
The Mailosaur API uses API keys to authenticate requests.
Authentication to the API is performed via HTTP Basic Auth. Your API key must be provided as the basic auth username value. You do not need to provide a password.
Your API keys carry many privileges, so always keep them secret and secure! Never share your API key in publicly-accessible areas such GitHub, client-side code, etc.
All API requests must be made over HTTPS. Calls made over plain HTTP will fail. API requests without authentication will also fail.
curl https://mailosaur.com/api/servers \
-u api:YOUR_API_KEY
Managing API keys
You can manage all your API keys in the Mailosaur Dashboard.
Errors
HTTP Status Codes
Mailosaur uses conventional HTTP response codes to indicate the success or failure of an API request. In general, codes in the 2xx
range indicate success, codes in the 4xx
range indicate an error that failed given the information provided (e.g., a required parameter was omitted), and codes in the 5xx
range indicate an error with Mailosaur’s servers (give us a shout in the unlikely event that you see one of those).
CODE | DESCRIPTION |
---|---|
200 OK | Request was successful. |
204 No Content | Request was successful, no response content. |
400 Bad Request | The request could not be handled, often due to missing a required parameter. |
401 Unauthorized | No valid API key provided. |
404 Not Found | The requested resource doesn’t exist. |
5XX Server Errors | Something went wrong at Mailosaur. (Give us a shout). |
Error handling
In case of an error the server will return as much information as possible. In the case of a 401
or 404
error the status code gives as much information as you’d need. But for 400
errors Mailosaur will return a JSON object containing the structure below.
Note that our client libraries convert responses to appropriate language-specific objects.
FIELD | DESCRIPTION |
---|---|
type | The type of error returned. |
message | A human-readable message providing more details about the error. |
parameters | A JSON object containing a key for each property name at fault, with a human-readable message per field. |
model | The request model that was sent and failed to be processed. |
Email and SMS testing
The Messages API allows you to list, search, view, modify and create email and SMS messages within your Mailosaur account.
Retrieve a message
If you are using one of Mailosaur’s client libraries, we highly recommend using the .Get
method instead of .GetById
, as it automatically waits for results to arrive!
Retrieves the detail for a single message. Simply supply the unique identifier for the required message.
To get the ID of a message you need to call one of our other API calls which returns a list of messages. Each message in the list will contain an ID which you can use to make this call.
Path parameters
- Name
id
- Type
string
- Required
required
- Description
- The identifier of the message to be retrieved. This can be found via other API calls such as List/Search.
GET /api/messages/:id
curl \
-u api:YOUR_API_KEY \
https://mailosaur.com/api/messages/MESSAGE_ID
{
"id": "77061c9f-da47-4009-9f33-9715a3bbf00c",
"received": "2019-08-06T17:44:07.197781+00:00",
"type": "Email",
"subject": "Email subject line",
"from": [{
"name": "Acme",
"email": "noreply@example.com"
}],
"to": [{
"name": "Jane Doe",
"email": "janedoe@abc1234.mailosaur.net"
}],
"cc": [],
"bcc": [],
"html": {
"links": [{
"href": "https://example.com/signup",
"text": "Sign Up Now"
}],
"images": [],
"body": "Lorem ipsum..."
},
"text": {
"links": [{
"href": "https://example.com/signup",
"text": "https://example.com/signup"
}],
"body": "Lorem ipsum..."
},
"attachments": [],
"metadata": {
"headers": [{
"field": "MIME-Version",
"value": "1.0"
}]
},
"server": "abcd1234"
}
Delete a message
Permanently deletes a message. This operation cannot be undone. Also deletes any attachments related to the message.
Path parameters
- Name
id
- Type
string
- Required
required
- Description
- The identifier of the message to be deleted.
DELETE /api/messages/:id
curl \
-X DELETE \
-u api:YOUR_API_KEY \
https://mailosaur.com/api/messages/MESSAGE_ID
List all messages
Returns a list of your messages in summary form. The summaries are returned sorted by received date, with the most recently-received messages appearing first.
Query parameters
- Name
server
- Type
string
- Required
required
- Description
- The identifier of the server hosting the messages.
- Name
receivedAfter
- Type
date/time
- Description
- Limits results to only messages received after this date/time.
- Name
page
- Type
integer
- Description
- Used in conjunction with `itemsPerPage` to support pagination.
- Name
itemsPerPage
- Type
integer
- Description
- A limit on the number of results to be returned per page. Can be set between 1 and 1000 items, the default is 50.
- Name
dir
- Type
string
- Description
- Optionally limits results based on the direction (`Sent` or `Received`), with the default being `Received`.
GET /api/messages?server=:server
curl \
-u api:YOUR_API_KEY \
https://mailosaur.com/api/messages?server=SERVER_ID
[
{
"id": "77061c9f-da47-4009-9f33-9715a3bbf00c",
"received": "2019-08-06T17:44:07.197781+00:00",
"type": "Email",
"subject": "Email subject line",
"from": [{
"name": "Acme",
"email": "noreply@example.com"
}],
"to": [{
"name": "Jane Doe",
"email": "janedoe@abc1234.mailosaur.net"
}],
"cc": [],
"bcc": []
}
]
Delete all messages
Permanently deletes all messages held by the specified server. This operation cannot be undone. Also deletes any attachments related to each message.
Query parameters
- Name
server
- Type
string
- Required
required
- Description
- The identifier of the server to be emptied.
DELETE /api/messages?server=:server
curl \
-X DELETE \
-u api:YOUR_API_KEY \
https://mailosaur.com/api/messages?server=SERVER_ID
Search for messages
If you are using one of Mailosaur’s client libraries, we highly recommend using the .Get
method instead of .Search
, as it automatically waits for results to arrive. It also returns the whole email/SMS, rather than just a message summary.
Returns a list of message summaries matching the specified search criteria, in summary form. The summaries are returned sorted by received date, with the most recently-received messages appearing first.
To get the full message content, including HTML & Text body content, you need to use the Retrieve a message endpoint. Alternatively you can search and retrieve in a single call by using our official client libraries.
Query parameters
- Name
server
- Type
string
- Required
required
- Description
- The identifier of the server hosting the messages.
- Name
receivedAfter
- Type
date/time
- Description
- Limits results to only messages received after this date/time.
- Name
page
- Type
integer
- Description
- Used in conjunction with `itemsPerPage` to support pagination.
- Name
itemsPerPage
- Type
integer
- Description
- A limit on the number of results to be returned per page. Can be set between 1 and 1000 items, the default is 50.
- Name
dir
- Type
string
- Description
- Optionally limits results based on the direction (`Sent` or `Received`), with the default being `Received`.
Body parameters
- Name
sentFrom
- Type
string
- Description
- The full email address or phone number from which the target message was sent.
- Name
sentTo
- Type
string
- Description
- The full email address or phone number to which the target message was sent.
- Name
subject
- Type
string
- Description
- The value to seek within the target email’s subject line.
- Name
body
- Type
string
- Description
- The value to seek within the target message’s HTML or text body.
- Name
match
- Type
string
- Description
- If set to `ALL` (default), then only results that match all specified criteria will be returned. If set to `ANY`, results that match any of the specified criteria will be returned.
POST /api/messages/search?server=:server
curl \
-X POST \
-H 'Content-Type: application/json' \
-d '{"sentTo":"someone@SERVER_ID.mailosaur.net"}' \
-u api:YOUR_API_KEY \
https://mailosaur.com/api/messages/search?server=SERVER_ID
[
{
"id": "77061c9f-da47-4009-9f33-9715a3bbf00c",
"received": "2019-08-06T17:44:07.197781+00:00",
"type": "Email",
"subject": "Email subject line",
"from": [{
"name": "Acme",
"email": "noreply@example.com"
}],
"to": [{
"name": "Jane Doe",
"email": "janedoe@abc1234.mailosaur.net"
}],
"cc": [],
"bcc": []
}
]
Forward a message
Forward an email or SMS message to a verified external email address. Supply the unique identifier for message you want to forward, as well as additional, relevant options.
To get the ID of a message you need to call one of our other API calls which returns a list of messages. Each message in the list will contain an ID which you can use to make this call.
Path parameters
- Name
id
- Type
string
- Required
required
- Description
- The identifier of the message to be forwarded. This can be found via other API calls such as Search for messages.
Body parameters
- Name
to
- Type
string
- Required
required
- Description
- The verified external email address to which the message should be sent.
- Name
subject
- Type
string
- Description
- Optionally override an email's subject line.
- Name
html
- Type
string
- Description
- Any HTML content to prefix the forwarded message with.
- Name
text
- Type
string
- Description
- Any plain text content to prefix the forwarded message with.
POST /api/messages/:id/forward
curl \
-X POST \
-H 'Content-Type: application/json' \
-d '{"to":"someone@example.com","text":"Example"}' \
-u api:YOUR_API_KEY \
https://mailosaur.com/api/messages/MESSAGE_ID/forward
{
"id": "77061c9f-da47-4009-9f33-9715a3bbf00c",
"received": "2019-08-06T17:44:07.197781+00:00",
"type": "Email",
"subject": "Email subject line",
"from": [{
"name": "Acme",
"email": "noreply@example.com"
}],
"to": [{
"name": "Jane Doe",
"email": "janedoe@abc1234.mailosaur.net"
}],
"cc": [],
"bcc": [],
"html": {
"links": [{
"href": "https://example.com/signup",
"text": "Sign Up Now"
}],
"images": [],
"body": "Lorem ipsum..."
},
"text": {
"links": [{
"href": "https://example.com/signup",
"text": "https://example.com/signup"
}],
"body": "Lorem ipsum..."
},
"attachments": [],
"metadata": {
"headers": [{
"field": "MIME-Version",
"value": "1.0"
}]
},
"server": "abcd1234"
}
Reply to a message
Reply to an email or SMS message. Supply the unique identifier for message you want to forward, as well as additional, relevant options.
Email replies can only be sent back to verified external email address. SMS replies can only contain approved phrases to prevent fraud.
To get the ID of a message you need to call one of our other API calls which returns a list of messages. Each message in the list will contain an ID which you can use to make this call.
Path parameters
- Name
id
- Type
string
- Required
required
- Description
- The identifier of the message to be replied to. This can be found via other API calls such as Search for messages.
Body parameters
- Name
subject
- Type
string
- Description
- Optionally override an email's subject line.
- Name
html
- Type
string
- Description
- Any HTML content to prefix the reply with.
- Name
text
- Type
string
- Description
- Any plain text content to prefix the reply with.
- Name
attachments
- Type
array
- Description
- An object array of base64-encoded attachment objects (`fileName`, `contentType`, `content`).
POST /api/messages/:id/reply
curl \
-X POST \
-H 'Content-Type: application/json' \
-d '{"text":"Example"}' \
-u api:YOUR_API_KEY \
https://mailosaur.com/api/messages/MESSAGE_ID/reply
{
"id": "77061c9f-da47-4009-9f33-9715a3bbf00c",
"received": "2019-08-06T17:44:07.197781+00:00",
"type": "Email",
"subject": "Email subject line",
"from": [{
"name": "Acme",
"email": "noreply@example.com"
}],
"to": [{
"name": "Jane Doe",
"email": "janedoe@abc1234.mailosaur.net"
}],
"cc": [],
"bcc": [],
"html": {
"links": [{
"href": "https://example.com/signup",
"text": "Sign Up Now"
}],
"images": [],
"body": "Lorem ipsum..."
},
"text": {
"links": [{
"href": "https://example.com/signup",
"text": "https://example.com/signup"
}],
"body": "Lorem ipsum..."
},
"attachments": [],
"metadata": {
"headers": [{
"field": "MIME-Version",
"value": "1.0"
}]
},
"server": "abcd1234"
}
Send an email
You can only send emails to verified external email address. Supply the unique identifier for server you want to send from, as well as additional, relevant options.
Query parameters
- Name
server
- Type
string
- Required
required
- Description
- The identifier of the server from which the email should be sent.
Body parameters
- Name
to
- Type
string
- Required
required
- Description
- The verified external email address to which the email should be sent.
- Name
from
- Type
string
- Description
- Optionally overrides of the message’s ‘from’ address. This **must** be an address ending with `YOUR_SERVER.mailosaur.net`, such as `my-emails @a1bcdef2.mailosaur.net`.
- Name
subject
- Type
string
- Required
required
- Description
- The subject line for an email.
- Name
html
- Type
string
- Description
- HTML content for the email.
- Name
text
- Type
string
- Description
- Plain text content for the email.
- Name
send
- Type
boolean
- Description
- If not `true`, then the email will be created in your server, but will not be sent.
- Name
attachments
- Type
array
- Description
- An object array of base64-encoded attachment objects (`fileName`, `contentType`, `content`).
POST /api/messages?server=:server
curl \
-X POST \
-H 'Content-Type: application/json' \
-d '{"to":"someone@example.com","subject":"Email from Mailosaur","text":"Example","send":true}' \
-u api:YOUR_API_KEY \
https://mailosaur.com/api/messages?server=SERVER_ID
{
"id": "77061c9f-da47-4009-9f33-9715a3bbf00c",
"received": "2019-08-06T17:44:07.197781+00:00",
"type": "Email",
"subject": "Email subject line",
"from": [{
"name": "Acme",
"email": "noreply@example.com"
}],
"to": [{
"name": "Jane Doe",
"email": "janedoe@abc1234.mailosaur.net"
}],
"cc": [],
"bcc": [],
"html": {
"links": [{
"href": "https://example.com/signup",
"text": "Sign Up Now"
}],
"images": [],
"body": "Lorem ipsum..."
},
"text": {
"links": [{
"href": "https://example.com/signup",
"text": "https://example.com/signup"
}],
"body": "Lorem ipsum..."
},
"attachments": [],
"metadata": {
"headers": [{
"field": "MIME-Version",
"value": "1.0"
}]
},
"server": "abcd1234"
}
Authenticator (2FA)
The Authenticator (2FA devices) API allows you to generate one-time passwords (OTPs) and virtual security devices, for the purpose of testing authentication systems.
Retrieve one-time password
Retrieves the one-time password for a given base32-encoded secret.
Body parameters
- Name
sharedSecret
- Type
string
- Required
required
- Description
- The base32-encoded shared secret to generate a one-time password for.
POST /api/devices/otp
curl \
-X POST \
-H 'Content-Type: application/json' \
-d '{"sharedSecret":"ONSWG4TFOQYTEMY="}' \
-u api:YOUR_API_KEY \
https://mailosaur.com/api/devices/otp
{
"code": "123456",
"expires": "2022-01-01T00:00:00Z"
}
List all devices
Returns a list of your virtual security devices.
GET /api/devices
curl \
-u api:YOUR_API_KEY \
https://mailosaur.com/api/devices
[
{
"id": "abcd1234",
"name": "Device name"
}
]
Create a device
Creates a new virtual security device and returns it.
Body parameters
- Name
name
- Type
string
- Required
required
- Description
- A name for the virtual device.
- Name
sharedSecret
- Type
string
- Required
required
- Description
- The base32-encoded shared secret to generate a one-time password for.
POST /api/devices
curl \
-X POST \
-H 'Content-Type: application/json' \
-d '{"name":"Example","sharedSecret":"ONSWG4TFOQYTEMY="}' \
-u api:YOUR_API_KEY \
https://mailosaur.com/api/devices
{
"id": "abcd1234",
"name": "My device"
}
Retrieve OTP for an existing device
Retrieves the current one-time password for an existing virtual security device. Simply supply the unique identifier for the required device.
Path parameters
- Name
id
- Type
string
- Required
required
- Description
- The identifier of the device to be retrieved.
GET /api/devices/:id/otp
curl \
-u api:YOUR_API_KEY \
https://mailosaur.com/api/devices/DEVICE_ID/otp
{
"code": "123456",
"expires": "2022-01-01T00:00:00Z"
}
Delete a device
Permanently deletes a device. This operation cannot be undone.
Path parameters
- Name
id
- Type
string
- Required
required
- Description
- The identifier of the device to be deleted.
DELETE /api/devices/:id
curl \
-X DELETE \
-u api:YOUR_API_KEY \
https://mailosaur.com/api/devices/DEVICE_ID
Files
The Files API allows you to download files, such as message attachments, from Mailosaur.
Download an attachment
Downloads a single attachment. Simply supply the unique identifier for the required attachment.
Path parameters
- Name
id
- Type
string
- Required
required
- Description
- The identifier of the attachment to be downloaded.
GET /api/files/attachments/:id
curl \
-o example.png \
-u api:YOUR_API_KEY \
https://mailosaur.com/api/files/attachments/ATTACHMENT_ID
Download EML
Downloads an EML file representing the specified email. Simply supply the unique identifier for the required email.
Path parameters
- Name
id
- Type
string
- Required
required
- Description
- The identifier of the email to be downloaded.
GET /api/files/email/:id
curl \
-o example.eml \
-u api:YOUR_API_KEY \
https://mailosaur.com/api/files/email/MESSAGE_ID
Analysis
The Analysis API allows you to analyse messages in more detail. For example, running a SpamAssassin report.
Perform a deliverability check
Generates a a deliverability report for the specified email. The domain of the sender is checked to ensure the deliverability of the email. Content of the email is also checked to highlight issues that may cause the email to be marked as illegitimate. Content is also checked via SpamAssassin which is one of the most common spam checkers on the market, these results can be used to understand how common spam checkers will view your email.
Path parameters
- Name
id
- Type
string
- Required
required
- Description
- The identifier of the email to be analyzed.
GET /api/analysis/deliverability/:id
curl \
-u api:YOUR_API_KEY \
https://mailosaur.com/api/analysis/deliverability/MESSAGE_ID
{
"spf": {
"result": "Pass",
"description": null,
"rawValue": null,
"tags": {}
},
"dkim": [
{
"result": "Pass",
"description": null,
"rawValue": null,
"tags": {}
}
],
"dmarc": {
"result": "Pass",
"description": null,
"rawValue": "v=DMARC1; p=reject; rua=mailto:dmarc@abc1234.mailosaur.net;",
"tags": {
"v": "DMARC1",
"p": "reject",
"rua": "mailto:dmarc@abc1234.mailosaur.net"
}
},
"blockLists": [
{
"id": "ABC123",
"name": "ABC",
"result": "Pass"
},
{
"id": "DEF123",
"name": "DEF",
"result": "Warning"
},
{
"id": "GHI123",
"name": "GHI",
"result": "Fail"
},
],
"content": {
"embed": false,
"iframe": false,
"object": false,
"script": false,
"shortUrls": false,
"textSize": 123,
"totalSize": 3456,
"missingAlt": false,
"missingListUnsubscribe": false
},
"dnsRecords": {
"a": [
"mailosaur.net. 30 IN A 192.168.1.1"
],
"mx": [
"mailosaur.net. 30 IN MX 0 mailosaur.net."
],
"ptr": []
},
"spamAssassin": {
"score": 0,
"result": "Pass",
"rules": [
{
"score": 0.0,
"rule": "ABC123",
"description": "ABC123"
}
]
}
}
Inboxes (servers)
The Servers API allows you to list, view, create, and modify the servers (inboxes) that store your email and SMS messages.
List all servers
Returns a list of your virtual SMTP servers. Servers are returned sorted in alphabetical order.
GET /api/servers
curl \
-u api:YOUR_API_KEY \
https://mailosaur.com/api/servers
[
{
"id": "abcd1234",
"name": "Server name",
"users": [],
"messages": 16
}
]
Create a server
Creates a new virtual SMTP server and returns it.
Body parameters
- Name
name
- Type
string
- Required
required
- Description
- The name of the server.
POST /api/servers
curl \
-X POST \
-H 'Content-Type: application/json' \
-d '{"name":"Example"}' \
-u api:YOUR_API_KEY \
https://mailosaur.com/api/servers
{
"id": "abcd1234",
"name": "Server name",
"users": [],
"messages": 0
}
Retrieve a server
Retrieves the detail for a single server. Simply supply the unique identifier for the required server.
Path parameters
- Name
id
- Type
string
- Required
required
- Description
- The identifier of the server to be retrieved.
GET /api/servers/:id
curl \
-u api:YOUR_API_KEY \
https://mailosaur.com/api/servers/SERVER_ID
{
"id": "abcd1234",
"name": "Server name",
"users": [],
"messages": 0
}
Retrieve server password
Retrieves the password, for use with SMTP and POP3, for a single server. Simply supply the unique identifier for the required server.
Path parameters
- Name
id
- Type
string
- Required
required
- Description
- The identifier of the server.
GET /api/servers/:id/password
curl \
-u api:YOUR_API_KEY \
https://mailosaur.com/api/servers/SERVER_ID/password
{
"value": "server-password"
}
Update a server
Updates a single server and returns it.
Path parameters
- Name
id
- Type
string
- Required
required
- Description
- The identifier of the server to be updated.
Body parameters
- Name
name
- Type
string
- Required
required
- Description
- The name of the server.
PUT /api/servers/:id
curl \
-X PUT \
-H 'Content-Type: application/json' \
-d '{"name":"Updated server name"}' \
-u api:YOUR_API_KEY \
https://mailosaur.com/api/servers/SERVER_ID
{
"id": "abcd1234",
"name": "Server name",
"users": [],
"messages": 0
}
Delete a server
Permanently deletes a server. This operation cannot be undone. Also deletes all messages and associated attachments within the server.
Path parameters
- Name
id
- Type
string
- Required
required
- Description
- The identifier of the server to be deleted.
DELETE /api/servers/:id
curl \
-X DELETE \
-u api:YOUR_API_KEY \
https://mailosaur.com/api/servers/SERVER_ID
Usage
The Usage API allows you to view your account limits, as well as list usage history to better understand how your Mailosaur account is utilized.
Retrieve account limits
Retrieve account usage limits. Details the current limits and usage for your account. This endpoint requires authentication with an account-level API key.
GET /api/usage/limits
curl \
-u api:YOUR_API_KEY \
https://mailosaur.com/api/usage/limits
{
"servers": {
"current": 27,
"limit": 50
},
"users": {
"current": 16,
"limit": 25
},
"email": {
"current": 12356,
"limit": 20000
},
"sms": {
"current": 271,
"limit": 500
},
"previews": {
"current": 89,
"limit": 200
},
"numbers": {
"current": 2,
"limit": 5
}
}
List usage transactions
Retrieves the last 31 days of transactional usage. This endpoint requires authentication with an account-level API key.
GET /api/usage/transactions
curl \
-u api:YOUR_API_KEY \
https://mailosaur.com/api/usage/transactions
{
"items": [
{
"timestamp": "2021-01-31T00:00:00Z",
"email": 2000,
"sms": 51,
"previews": 0
}
]
}