Messages
Messages are resources that are created from a single Email API request.
Get a list of messages
Retrieve a information about all messaged with this GET
request.
Request
GET https://api.mailersend.com/v1/messages
Request parameters
Query parameter | Type | Required | Limitations | Details |
---|---|---|---|---|
page | int | no | ||
limit | int | no | Min: 10 , Max: 100 | Default: 25 |
use MailerSend\MailerSend;
$mailersend = new MailerSend(['api_key' => 'key']);
$mailersend->messages->get($limit = 100, $page = 3);
import 'dotenv/config';
import { MailerSend} from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.message.list()
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
from mailersend import messages
api_key = "API key here"
mailer = messages.NewMessage(api_key)
mailer.get_messages()
package main
import (
"context"
"log"
"time"
"github.com/mailersend/mailersend-go"
)
var APIKey = "Api Key Here"
func main() {
// Create an instance of the mailersend client
ms := mailersend.NewMailersend(APIKey)
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
options := &mailersend.ListMessageOptions{
Page: 1,
Limit: 25,
}
_, _, err := ms.Message.List(ctx, options)
if err != nil {
log.Fatal(err)
}
}
import com.mailersend.sdk.MailerSend;
import com.mailersend.sdk.exceptions.MailerSendException;
import com.mailersend.sdk.messages.Message;
import com.mailersend.sdk.messages.MessagesList;
public void MessagesList() {
MailerSend ms = new MailerSend();
ms.setToken("token");
try {
MessagesList list = ms.messages().getMessages();
for (MessageListItem message : list.messages) {
System.out.println(message.id);
System.out.println(message.createdAt.toString());
}
} catch (MailerSendException e) {
e.printStackTrace();
}
}
require "mailersend-ruby"
ms_messages = Mailersend::Messages.new
ms_messages.list(page: 1, limit: 10)
Responses
Valid
Response Code: 200 OK
Response Headers:
content-type: application/json
{
"data": [
{
"id": "5ee0b182b251345e407c935a",
"created_at": "2020-06-10T10:10:10.377000Z",
"updated_at": "2020-06-10T10:10:10.377000Z"
},
{
"id": "5ee0b182b251345e407c935c",
"created_at": "2020-06-10T10:10:10.385000Z",
"updated_at": "2020-06-10T10:10:10.385000Z"
},
{
"id": "5ee0b182b251345e407c935d",
"created_at": "2020-06-10T10:10:10.386000Z",
"updated_at": "2020-06-10T10:10:10.386000Z"
},
{
"id": "5ee0b182b251345e407c935e",
"created_at": "2020-06-10T10:10:10.388000Z",
"updated_at": "2020-06-10T10:10:10.388000Z"
}
],
"links": {
"first": "https:\/\/www.mailersend.io\/api\/v1\/messages?page=1",
"last": "https:\/\/www.mailersend.io\/api\/v1\/messages?page=1",
"prev": null,
"next": null
},
"meta": {
"current_page": 1,
"from": 1,
"last_page": 1,
"path": "https:\/\/www.mailersend.io\/api\/v1\/messages",
"per_page": 25,
"to": 4,
"total": 4
}
}
Error
Response Code: 422 Unprocessable Entity
See - Validation errors
Get information for a single message
Overview
Retrieve information for a single message with this GET
request.
Request
GET https://api.mailersend.com/v1/messages/{message_id}
Request parameters
URL parameter | Type | Required | Limitations | Details |
---|---|---|---|---|
message_id | string | yes |
use MailerSend\MailerSend;
$mailersend = new MailerSend(['api_key' => 'key']);
$mailersend->messages->find('message_id');
import 'dotenv/config';
import { MailerSend} from "mailersend";
const mailerSend = new MailerSend({
apiKey: process.env.API_KEY,
});
mailerSend.email.message.single("message_id")
.then((response) => console.log(response.body))
.catch((error) => console.log(error.body));
from mailersend import messages
api_key = "API key here"
mailer = messages.NewMessage(api_key)
mailer.get_message_by_id("message-id")
package main
import (
"context"
"log"
"time"
"github.com/mailersend/mailersend-go"
)
var APIKey = "Api Key Here"
func main() {
// Create an instance of the mailersend client
ms := mailersend.NewMailersend(APIKey)
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
messageID := "message-id"
_, _, err := ms.Message.Get(ctx, messageID)
if err != nil {
log.Fatal(err)
}
}
import com.mailersend.sdk.MailerSend;
import com.mailersend.sdk.exceptions.MailerSendException;
import com.mailersend.sdk.messages.Message;
import com.mailersend.sdk.messages.MessagesListItem;
public void SingleMessage() {
MailerSend ms = new MailerSend();
ms.setToken("token");
try {
Message message = ms.messages().getMessage("message id");
System.out.println(message.id);
System.out.println(message.createdAt.toString());
System.out.println(message.domain.name);
} catch (MailerSendException e) {
e.printStackTrace();
}
}
require "mailersend-ruby"
ms_messages = Mailersend::Messages.new
ms_messages.single(message_id: "mess11454")
Responses
Valid
Response key | Type | Details |
---|---|---|
data.emails.* | object[] | Will include email data if it has been created in the database. |
data.domain.* | object | Includes data for a domain that is attached to the message. |
Response Code: 200 OK
Response Headers:
content-type: application/json
{
"data": {
"id": "5ee0b183b251345e407c936a",
"created_at": "2020-06-10T10:10:11.231000Z",
"updated_at": "2020-06-10T10:10:11.231000Z",
"emails": [],
"domain": {
"id": "zo8zdo",
"name": "example.net",
"dkim": true,
"spf": true,
"mx": false,
"tracking": false,
"is_verified": true,
"is_cname_verified": false,
"is_dns_active": true,
"is_cname_active": false,
"is_tracking_allowed": false,
"has_not_queued_messages": true,
"not_queued_messages_count": 1,
"domain_settings": {
"send_paused": false,
"track_clicks": true,
"track_opens": true,
"track_unsubscribe": true,
"track_unsubscribe_html": "<p>Click here to <a href=\"{{unsubscribe}}\">unsubscribe<\/a><\/p>",
"track_unsubscribe_plain": "Click here to unsubscribe: {{unsubscribe}}",
"track_content": true,
"custom_tracking_enabled": false,
"custom_tracking_subdomain": "email"
},
"created_at": "2020-06-10 10:10:11",
"updated_at": "2020-06-10 10:10:11"
}
}
}
Error
Response Code: 404 Not Found