openapi: 3.1.0 info: description: Test email sending in a safe environment version: 2.0.0 title: Email Sandbox contact: name: Mailtrap url: 'https://docs.mailtrap.io' email: support@mailtrap.io license: name: Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) url: 'https://creativecommons.org/licenses/by-sa/4.0/' security: - HeaderAuth: [] - BearerAuth: [] servers: - description: Mailtrap API url: 'https://mailtrap.io' tags: - name: Projects x-page-title: Projects x-page-description: Organize test environments description: Interactions with projects - name: Sandboxes x-page-title: Sandboxes x-page-description: Manage test sandboxes description: | Manage Sandboxes for email testing. Capture and inspect emails without delivering them to real recipients. This is ideal for development, staging, and QA environments. ### Get your Sandbox ID To use the Sandbox API, you need a Sandbox ID. You can get it in one of the following ways. #### Option 1: From the sandbox URL 1. Open your Sandbox in Mailtrap. 2. Copy the ID from the sandbox URL. Example: - URL: https://mailtrap.io/sandboxes/2564102/settings - Sandbox ID: 2564102 #### Option 2: Via the API Use the `Get a list of sandboxes` endpoint to retrieve all Sandboxes in your account. - name: Messages x-page-title: Messages x-page-description: Inspect captured emails description: Interactions with messages - name: Attachments x-page-title: Attachments x-page-description: Handle email attachments description: Interactions with attachments paths: '/api/sandboxes': get: summary: Get a list of sandboxes description: Get a list of sandboxes. tags: - Sandboxes responses: '200': $ref: '#/components/responses/SandboxesResponse' '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': $ref: '#/components/responses/PERMISSION_DENIED' x-codeSamples: - lang: shell label: 'cURL' source: | curl -X GET https://mailtrap.io/api/sandboxes \ -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | const { MailtrapClient } = require("mailtrap"); const TOKEN = "YOUR_API_KEY"; const ACCOUNT_ID = "YOUR_ACCOUNT_ID"; const client = new MailtrapClient({ token: TOKEN, accountId: ACCOUNT_ID }); async function getInboxes() { const inboxes = await client.testing.inboxes.getList(); } getInboxes(); - lang: php label: PHP source: | inboxes($accountId); $response = $sandboxInboxes->getList(); var_dump(ResponseHelper::toArray($response)); - lang: python label: Python source: | import mailtrap as mt API_TOKEN = "YOUR_API_KEY" ACCOUNT_ID = "YOUR_ACCOUNT_ID" client = mt.MailtrapClient(token=API_TOKEN, account_id=ACCOUNT_ID) inboxes_api = client.testing_api.inboxes inboxes = inboxes_api.get_list() print(inboxes) - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: ENV['MAILTRAP_API_KEY']) inboxes = Mailtrap::InboxesAPI.new(YOUR_ACCOUNT_ID, client) inboxes.list.each do |inbox| puts "Inbox: #{inbox.name} (ID: #{inbox.id})" end - lang: csharp label: .NET source: | using Mailtrap; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var inboxes = await client .Account(YOUR_ACCOUNT_ID) .Inboxes() .GetAll(); Console.WriteLine(inboxes); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; var config = new MailtrapConfig.Builder() .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory .createMailtrapClient(config); var inboxes = client.testingApi().inboxes() .getInboxes(accountId); System.out.println(inboxes); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } sandboxes, _, err := client.Sandboxes.List(context.Background()) if err != nil { log.Fatal(err) } for _, sandbox := range sandboxes { fmt.Printf("%d %s (%d message(s), %d unread)\n", sandbox.ID, sandbox.Name, sandbox.EmailsCount, sandbox.EmailsUnreadCount) } } - lang: hcl label: Terraform source: | # looking a sandbox up by name lists them: GET /api/sandboxes terraform { required_providers { mailtrap = { source = "mailtrap/mailtrap" } } } # The token is read from the MAILTRAP_API_TOKEN environment variable. provider "mailtrap" {} data "mailtrap_sandbox" "staging" { name = "Staging inbox" } output "sandbox_id" { value = data.mailtrap_sandbox.staging.id } operationId: getSandboxes '/api/projects': post: summary: Create project description: The project name is min 2 characters and max 100 characters long. tags: - Projects requestBody: content: application/json: schema: type: object properties: project: type: object properties: name: type: string example: project: name: My New Project responses: '200': $ref: '#/components/responses/ProjectResponse' '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': $ref: '#/components/responses/PERMISSION_DENIED' operationId: createProject x-codeSamples: - lang: shell label: 'cURL' source: | curl -X POST https://mailtrap.io/api/projects \ -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "project": { "name": "My New Project" } }' - lang: javascript label: Node.js source: | import { MailtrapClient } from "mailtrap"; const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId: ACCOUNT_ID }); async function createProject() { const project = await client.testing.projects.create({ name: 'My New Project' }); } createProject(); - lang: php label: PHP source: | projects($accountId); $response = $sandboxProjects->create('My New Project'); var_dump(ResponseHelper::toArray($response)); - lang: python label: Python source: | import mailtrap as mt client = mt.MailtrapClient( token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID" ) project = client.testing_api.projects.create( project_params=mt.ProjectParams(name="My New Project") ) print(project) - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') projects = Mailtrap::ProjectsAPI.new( YOUR_ACCOUNT_ID, client ) project = projects.create( name: 'Example Project' ) puts project - lang: csharp label: .NET source: | using Mailtrap; using Mailtrap.Projects.Requests; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var project = await client .Account(YOUR_ACCOUNT_ID) .Projects() .Create(new CreateProjectRequest("My New Project")); Console.WriteLine(project.Name); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; import io.mailtrap.model.request.projects.ProjectRequest; var config = new MailtrapConfig.Builder() .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory .createMailtrapClient(config); var request = new ProjectRequest( new ProjectRequest.ProjectData("My New Project") ); var project = client.testingApi().projects() .createProject(accountId, request); System.out.println(project); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } project, _, err := client.Projects.Create(context.Background(), "My project") if err != nil { log.Fatal(err) } fmt.Printf("created project %d (%s)\n", project.ID, project.Name) } - lang: hcl label: Terraform source: | # terraform apply creates the project: POST /api/projects # Provider docs: https://registry.terraform.io/providers/mailtrap/mailtrap/latest/docs terraform { required_providers { mailtrap = { source = "mailtrap/mailtrap" } } } # The token is read from the MAILTRAP_API_TOKEN environment variable. provider "mailtrap" {} resource "mailtrap_project" "testing" { name = "My project" } get: summary: Get a list of projects description: List projects and their sandboxes to which the API token has access. tags: - Projects responses: '200': $ref: '#/components/responses/ProjectsResponse' '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': $ref: '#/components/responses/PERMISSION_DENIED' operationId: getProjects x-codeSamples: - lang: shell label: 'cURL' source: | curl -X GET https://mailtrap.io/api/projects \ -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | import { MailtrapClient } from "mailtrap"; const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId: ACCOUNT_ID }); async function getProjects() { const projects = await client.testing.projects.getList(); } getProjects(); - lang: php label: PHP source: | projects($accountId); $response = $sandboxProjects->getList(); var_dump(ResponseHelper::toArray($response)); - lang: python label: Python source: | import mailtrap as mt client = mt.MailtrapClient( token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID" ) projects = client.testing_api.projects.get_list() for project in projects: print(f"Project: {project.name}, ID: {project.id}") - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') projects = Mailtrap::ProjectsAPI.new( YOUR_ACCOUNT_ID, client ) all_projects = projects.list all_projects.each do |project| puts "Project: #{project.name}, ID: #{project.id}" end - lang: csharp label: .NET source: | using Mailtrap; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var projects = await client .Account(YOUR_ACCOUNT_ID) .Projects() .GetAll(); foreach (var project in projects) { Console.WriteLine($"Project: {project.Name}, ID: {project.Id}"); } - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; var config = new MailtrapConfig.Builder() .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory .createMailtrapClient(config); var projects = client.testingApi().projects().getProjects(accountId); for (var project : projects) { System.out.println("Project: " + project.getName() + ", ID: " + project.getId()); } - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } projects, _, err := client.Projects.List(context.Background()) if err != nil { log.Fatal(err) } for _, project := range projects { fmt.Printf("%d %s (%d sandbox(es))\n", project.ID, project.Name, len(project.Sandboxes)) } } - lang: hcl label: Terraform source: | # looking a project up by name lists them: GET /api/projects terraform { required_providers { mailtrap = { source = "mailtrap/mailtrap" } } } # The token is read from the MAILTRAP_API_TOKEN environment variable. provider "mailtrap" {} data "mailtrap_project" "testing" { name = "My project" } output "project_id" { value = data.mailtrap_project.testing.id } '/api/projects/{project_id}': get: summary: Get project by ID description: Get the project and its sandboxes. tags: - Projects responses: '200': $ref: '#/components/responses/ProjectResponse' '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': $ref: '#/components/responses/PERMISSION_DENIED' '404': $ref: '#/components/responses/NOT_FOUND' operationId: getProject x-codeSamples: - lang: shell label: 'cURL' source: | curl -X GET https://mailtrap.io/api/projects/{project_id} \ -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | import { MailtrapClient } from "mailtrap"; const client = new MailtrapClient({ token: process.env.MAILTRAP_API_KEY, accountId: YOUR_ACCOUNT_ID }); async function getProject() { const projectId = 12345; const project = await client.testing.projects.get(projectId); console.log("Project:", project); } getProject(); - lang: php label: PHP source: | projects($accountId); $projectId = $_ENV['MAILTRAP_PROJECT_ID']; $response = $sandboxProjects->getById($projectId); var_dump(ResponseHelper::toArray($response)); - lang: python label: Python source: | import mailtrap as mt client = mt.MailtrapClient( token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID" ) # Get project by ID project_id = 12345 project = client.testing_api.projects.get_by_id(project_id) print(f"Project: {project.name}") - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') projects = Mailtrap::ProjectsAPI.new( YOUR_ACCOUNT_ID, client ) # Get project by ID project_id = 12345 project = projects.get(project_id) puts "Project: #{project.name}" - lang: csharp label: .NET source: | using Mailtrap; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var projectId = 12345; var project = await client .Account(YOUR_ACCOUNT_ID) .Project(projectId) .GetDetails(); Console.WriteLine($"Project: {project.Name}"); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; var config = new MailtrapConfig.Builder() .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory .createMailtrapClient(config); long projectId = 12345L; var project = client.testingApi().projects() .getProject(accountId, projectId); System.out.println("Project: " + project.getName()); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } project, _, err := client.Projects.Get(context.Background(), 1000001) if err != nil { log.Fatal(err) } fmt.Printf("%d %s\n", project.ID, project.Name) } - lang: hcl label: Terraform source: | # terraform apply reads the project: GET /api/projects/{project_id} terraform { required_providers { mailtrap = { source = "mailtrap/mailtrap" } } } # The token is read from the MAILTRAP_API_TOKEN environment variable. provider "mailtrap" {} data "mailtrap_project" "testing" { id = 1000001 } output "project_name" { value = data.mailtrap_project.testing.name } patch: summary: Update project description: Update project name. The project name is min 2 characters and max 100 characters long. tags: - Projects x-codeSamples: - lang: shell label: 'cURL' source: | curl -X PATCH https://mailtrap.io/api/projects/{project_id} \ -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "project": { "name": "Updated Project Name" } }' - lang: javascript label: Node.js source: | import { MailtrapClient } from "mailtrap"; const client = new MailtrapClient({ token: process.env.MAILTRAP_API_KEY, accountId: YOUR_ACCOUNT_ID }); async function updateProject() { const projectId = 12345; const updatedProject = await client.testing.projects.update( projectId, "Updated Project Name" ); console.log("Project updated:", updatedProject); } updateProject(); - lang: php label: PHP source: | projects($accountId); $projectId = $_ENV['MAILTRAP_PROJECT_ID']; $newProjectName = 'Updated Project Name'; $response = $sandboxProjects->updateName($projectId, $newProjectName); var_dump(ResponseHelper::toArray($response)); - lang: python label: Python source: | import mailtrap as mt client = mt.MailtrapClient( token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID" ) # Update project project_id = 12345 updated_project = client.testing_api.projects.update( project_id, mt.ProjectParams(name="Updated Project Name") ) print(f"Project updated: {updated_project.name}") - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') projects = Mailtrap::ProjectsAPI.new( YOUR_ACCOUNT_ID, client ) # Update project project_id = 12345 updated_project = projects.update( project_id, name: 'Updated Project Name' ) puts "Project updated: #{updated_project.name}" - lang: csharp label: .NET source: | using Mailtrap; using Mailtrap.Projects.Requests; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var projectId = 12345; var updateRequest = new UpdateProjectRequest("Updated Project Name"); var updatedProject = await client .Account(YOUR_ACCOUNT_ID) .Project(projectId) .Update(updateRequest); Console.WriteLine($"Project updated: {updatedProject.Name}"); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; import io.mailtrap.model.request.projects.ProjectRequest; var config = new MailtrapConfig.Builder() .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory .createMailtrapClient(config); long projectId = 12345L; var request = new ProjectRequest( new ProjectRequest.ProjectData("Updated Project Name") ); var updatedProject = client.testingApi().projects() .updateProject(accountId, projectId, request); System.out.println("Project updated: " + updatedProject.getName()); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } project, _, err := client.Projects.Update(context.Background(), 1000001, "Renamed project") if err != nil { log.Fatal(err) } fmt.Printf("renamed project %d to %s\n", project.ID, project.Name) } requestBody: content: application/json: schema: type: object properties: project: type: object properties: name: type: string example: project: name: New Project Name responses: '200': $ref: '#/components/responses/UpdateProjectResponse' '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': $ref: '#/components/responses/PERMISSION_DENIED' '404': $ref: '#/components/responses/NOT_FOUND' operationId: updateProject delete: summary: Delete project description: Delete project and its sandboxes. tags: - Projects x-codeSamples: - lang: shell label: 'cURL' source: | curl -X DELETE https://mailtrap.io/api/projects/{project_id} \ -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | import { MailtrapClient } from "mailtrap"; const client = new MailtrapClient({ token: process.env.MAILTRAP_API_KEY, accountId: YOUR_ACCOUNT_ID }); async function deleteProject() { const projectId = 12345; const result = await client.testing.projects.delete(projectId); console.log("Project deleted:", result); } deleteProject(); - lang: php label: PHP source: | projects($accountId); $projectId = $_ENV['MAILTRAP_PROJECT_ID']; $response = $sandboxProjects->delete($projectId); var_dump($response->getStatusCode()); - lang: python label: Python source: | import mailtrap as mt client = mt.MailtrapClient( token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID" ) # Delete project project_id = 12345 result = client.testing_api.projects.delete(project_id) print(f"Project deleted: {result.id}") - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') projects = Mailtrap::ProjectsAPI.new( YOUR_ACCOUNT_ID, client ) # Delete project project_id = 12345 result = projects.delete(project_id) puts "Project deleted: #{result.id}" - lang: csharp label: .NET source: | using Mailtrap; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var projectId = 12345; var deletedProject = await client .Account(YOUR_ACCOUNT_ID) .Project(projectId) .Delete(); Console.WriteLine($"Project deleted: {deletedProject.Id}"); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; var config = new MailtrapConfig.Builder() .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory .createMailtrapClient(config); long projectId = 12345L; var deletedProject = client.testingApi().projects() .deleteProject(accountId, projectId); System.out.println("Project deleted: " + deletedProject.getId()); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } if _, err := client.Projects.Delete(context.Background(), 1000001); err != nil { log.Fatal(err) } fmt.Println("project deleted") } responses: '200': description: Returns id of the deleted project. content: application/json: schema: type: object properties: id: type: integer example: id: 4046 '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': $ref: '#/components/responses/PERMISSION_DENIED' '404': $ref: '#/components/responses/NOT_FOUND' operationId: deleteProject parameters: - $ref: '#/components/parameters/project_id' '/api/projects/{project_id}/sandboxes': post: summary: Create a sandbox description: Create a sandbox in a project. tags: - Sandboxes requestBody: content: application/json: schema: type: object properties: sandbox: type: object properties: name: type: string example: sandbox: name: My new sandbox responses: '200': $ref: '#/components/responses/SandboxResponse' '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': $ref: '#/components/responses/PERMISSION_DENIED' '404': $ref: '#/components/responses/NOT_FOUND' operationId: createSandbox x-codeSamples: - lang: shell label: 'cURL' source: | curl -X POST https://mailtrap.io/api/projects/{project_id}/sandboxes \ -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "sandbox": { "name": "My Test Sandbox" } }' - lang: javascript label: Node.js source: | import { MailtrapClient } from "mailtrap"; const TOKEN = "YOUR_API_KEY"; const ACCOUNT_ID = "YOUR_ACCOUNT_ID"; const client = new MailtrapClient({ token: TOKEN, accountId: ACCOUNT_ID }); async function createInbox() { const projectId = 12345; const inbox = await client.testing.inboxes.create( projectId, 'My Test Inbox' ); console.log(`Inbox created: ${inbox.name}`); console.log(`SMTP credentials - User: ${inbox.username}`); } createInbox(); - lang: php label: PHP source: | inboxes($accountId); $response = $sandboxInboxes->create($projectId, 'My Test Inbox'); var_dump(ResponseHelper::toArray($response)); - lang: python label: Python source: | import mailtrap as mt client = mt.MailtrapClient( token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID" ) project_id = 12345 inbox = client.testing_api.inboxes.create( project_id=project_id, inbox_params=mt.InboxParams(name="My Test Inbox") ) print(f"Inbox created: {inbox.name}") print(f"SMTP credentials - User: {inbox.username}") - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: ENV['MAILTRAP_API_KEY']) inboxes = Mailtrap::InboxesAPI.new(YOUR_ACCOUNT_ID, client) inbox = inboxes.create(name: 'My Test Inbox', project_id: PROJECT_ID) puts "Inbox created: #{inbox.name}" - lang: csharp label: .NET source: | using Mailtrap; using Mailtrap.Inboxes.Requests; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var projectId = 12345; var inbox = await client .Account(YOUR_ACCOUNT_ID) .Inboxes() .Create(new CreateInboxRequest(projectId, "My Test Inbox")); Console.WriteLine($"Inbox created: {inbox.Name}"); Console.WriteLine($"SMTP credentials - User: {inbox.UserName}"); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; import io.mailtrap.model.request.inbox.CreateInboxRequest; var config = new MailtrapConfig.Builder() .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory .createMailtrapClient(config); var request = new CreateInboxRequest( new CreateInboxRequest.InboxCreateData("My Test Inbox") ); long projectId = 12345L; var inbox = client.testingApi().inboxes() .createInbox(accountId, projectId, request); System.out.println("Inbox created: " + inbox.getName()); System.out.println("SMTP credentials - User: " + inbox.getUsername()); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } sandbox, _, err := client.Sandboxes.Create(context.Background(), 1000001, "Staging inbox") if err != nil { log.Fatal(err) } fmt.Printf("created sandbox %d (%s)\n", sandbox.ID, sandbox.Name) } - lang: hcl label: Terraform source: | # terraform apply creates the sandbox: POST /api/projects/{project_id}/sandboxes # Provider docs: https://registry.terraform.io/providers/mailtrap/mailtrap/latest/docs terraform { required_providers { mailtrap = { source = "mailtrap/mailtrap" } } } # The token is read from the MAILTRAP_API_TOKEN environment variable. provider "mailtrap" {} resource "mailtrap_project" "testing" { name = "My project" } # Create only accepts name and project_id. Setting email_username makes the same # apply follow up with a PATCH. resource "mailtrap_sandbox" "staging" { name = "Staging inbox" project_id = mailtrap_project.testing.id } parameters: - $ref: '#/components/parameters/project_id' '/api/sandboxes/{sandbox_id}': get: summary: Get sandbox attributes description: Get sandbox attributes by sandbox id. See the list of attributes in the example tags: - Sandboxes responses: '200': $ref: '#/components/responses/SandboxResponse' '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': $ref: '#/components/responses/PERMISSION_DENIED' '404': $ref: '#/components/responses/NOT_FOUND' x-codeSamples: - lang: shell label: 'cURL' source: | curl -X GET https://mailtrap.io/api/sandboxes/{sandbox_id} \ -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | const { MailtrapClient } = require("mailtrap"); const TOKEN = "YOUR_API_KEY"; const ACCOUNT_ID = "YOUR_ACCOUNT_ID"; const client = new MailtrapClient({ token: TOKEN, accountId: ACCOUNT_ID }); async function getInboxAttributes() { const inboxId = 12345; const inboxAttributes = await client.testing.inboxes.getInboxAttributes(inboxId); console.log(inboxAttributes); } getInboxAttributes(); - lang: php label: PHP source: | inboxes($accountId); $inboxId = $_ENV['MAILTRAP_INBOX_ID']; $response = $sandboxInboxes->getInboxAttributes($inboxId); var_dump(ResponseHelper::toArray($response)); - lang: python label: Python source: | import mailtrap as mt API_TOKEN = "YOUR_API_KEY" ACCOUNT_ID = "YOUR_ACCOUNT_ID" client = mt.MailtrapClient(token=API_TOKEN, account_id=ACCOUNT_ID) inboxes_api = client.testing_api.inboxes inbox_id = 12345 inbox_attributes = inboxes_api.get_by_id(inbox_id) print(inbox_attributes) - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: ENV['MAILTRAP_API_KEY']) inboxes = Mailtrap::InboxesAPI.new(YOUR_ACCOUNT_ID, client) inbox = inboxes.get(INBOX_ID) puts "Inbox: #{inbox}" - lang: csharp label: .NET source: | using Mailtrap; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var inboxId = 12345; var inbox = await client .Account(YOUR_ACCOUNT_ID) .Inbox(inboxId) .GetDetails(); Console.WriteLine(inbox); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; var config = new MailtrapConfig.Builder() .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory .createMailtrapClient(config); long inboxId = 12345L; var inboxAttributes = client.testingApi().inboxes() .getInboxAttributes(accountId, inboxId); System.out.println(inboxAttributes); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } sandbox, _, err := client.Sandboxes.Get(context.Background(), 3000001) if err != nil { log.Fatal(err) } fmt.Printf("%s: %s@%s, SMTP %v\n", sandbox.Name, sandbox.Username, sandbox.Domain, sandbox.SMTPPorts) } - lang: hcl label: Terraform source: | # terraform apply reads the sandbox: GET /api/sandboxes/{sandbox_id} terraform { required_providers { mailtrap = { source = "mailtrap/mailtrap" } } } # The token is read from the MAILTRAP_API_TOKEN environment variable. provider "mailtrap" {} data "mailtrap_sandbox" "staging" { id = 3000001 } output "smtp_host" { value = data.mailtrap_sandbox.staging.domain } operationId: getSandboxAttributes delete: summary: Delete a sandbox description: Delete a sandbox with all its emails. tags: - Sandboxes responses: '200': $ref: '#/components/responses/SandboxResponse' '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': $ref: '#/components/responses/PERMISSION_DENIED' '404': $ref: '#/components/responses/NOT_FOUND' x-codeSamples: - lang: shell label: 'cURL' source: | curl -X DELETE https://mailtrap.io/api/sandboxes/{sandbox_id} \ -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | const { MailtrapClient } = require("mailtrap"); const TOKEN = "YOUR_API_KEY"; const ACCOUNT_ID = "YOUR_ACCOUNT_ID"; const client = new MailtrapClient({ token: TOKEN, accountId: ACCOUNT_ID }); async function deleteInbox() { const inboxId = 12345; const result = await client.testing.inboxes.delete(inboxId); console.log(result); } deleteInbox(); - lang: php label: PHP source: | inboxes($accountId); $inboxId = $_ENV['MAILTRAP_INBOX_ID']; $response = $sandboxInboxes->delete($inboxId); var_dump($response->getStatusCode()); - lang: python label: Python source: | import mailtrap as mt API_TOKEN = "YOUR_API_KEY" ACCOUNT_ID = "YOUR_ACCOUNT_ID" client = mt.MailtrapClient(token=API_TOKEN, account_id=ACCOUNT_ID) inboxes_api = client.testing_api.inboxes inbox_id = 12345 result = inboxes_api.delete(inbox_id) print(result) - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: ENV['MAILTRAP_API_KEY']) inboxes = Mailtrap::InboxesAPI.new(YOUR_ACCOUNT_ID, client) inboxes.delete(INBOX_ID) - lang: csharp label: .NET source: | using Mailtrap; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var inboxId = 12345; var deletedInbox = await client .Account(YOUR_ACCOUNT_ID) .Inbox(inboxId) .Delete(); Console.WriteLine(deletedInbox); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; var config = new MailtrapConfig.Builder() .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory .createMailtrapClient(config); long inboxId = 12345L; var deletedInbox = client.testingApi().inboxes() .deleteInbox(ACCOUNT_ID, inboxId); System.out.println(deletedInbox); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } // Unlike most deletes, this one returns the deleted sandbox. sandbox, _, err := client.Sandboxes.Delete(context.Background(), 3000001) if err != nil { log.Fatal(err) } fmt.Printf("deleted sandbox %d (%s)\n", sandbox.ID, sandbox.Name) } operationId: deleteSandbox patch: summary: Update a sandbox description: 'Update sandbox name, sandbox email username.' tags: - Sandboxes requestBody: content: application/json: schema: type: object properties: sandbox: type: object properties: name: type: string email_username: type: string example: sandbox: name: New Sandbox Name email_username: my-username responses: '200': $ref: '#/components/responses/SandboxResponse' '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': $ref: '#/components/responses/PERMISSION_DENIED' '404': $ref: '#/components/responses/NOT_FOUND' x-codeSamples: - lang: shell label: 'cURL' source: | curl -X PATCH https://mailtrap.io/api/sandboxes/{sandbox_id} \ -H 'Authorization: Bearer YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "sandbox": { "name": "Updated Sandbox Name", "email_username": "new-username" } }' - lang: javascript label: Node.js source: | const { MailtrapClient } = require("mailtrap"); const TOKEN = "YOUR_API_KEY"; const ACCOUNT_ID = "YOUR_ACCOUNT_ID"; const client = new MailtrapClient({ token: TOKEN, accountId: ACCOUNT_ID }); async function updateInbox() { const inboxId = 12345; const updatedInbox = await client.testing.inboxes.updateInbox( inboxId, { name: 'Updated Inbox Name', emailUsername: 'new-username' } ); console.log(updatedInbox); } updateInbox(); - lang: php label: PHP source: | inboxes($accountId); $inboxId = $_ENV['MAILTRAP_INBOX_ID']; $response = $sandboxInboxes->update( $inboxId, new Inbox('Updated Inbox Name', 'new-username') ); var_dump(ResponseHelper::toArray($response)); - lang: python label: Python source: | import mailtrap as mt API_TOKEN = "YOUR_API_KEY" ACCOUNT_ID = "YOUR_ACCOUNT_ID" client = mt.MailtrapClient(token=API_TOKEN, account_id=ACCOUNT_ID) inboxes_api = client.testing_api.inboxes inbox_id = 12345 updated_inbox = inboxes_api.update( inbox_id, mt.UpdateInboxParams(name="Updated Inbox Name", email_username="new-username") ) print(updated_inbox) - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: ENV['MAILTRAP_API_KEY']) inboxes = Mailtrap::InboxesAPI.new(YOUR_ACCOUNT_ID, client) inboxes.update(INBOX_ID, name: 'Updated Inbox Name') - lang: csharp label: .NET source: | using Mailtrap; using Mailtrap.Inboxes.Requests; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var inboxId = 12345; var updateRequest = new UpdateInboxRequest { Name = "Updated Inbox Name", EmailUsername = "new-username" }; var updatedInbox = await client .Account(YOUR_ACCOUNT_ID) .Inbox(inboxId) .Update(updateRequest); Console.WriteLine(updatedInbox); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; import io.mailtrap.model.request.inboxes.UpdateInboxRequest; var config = new MailtrapConfig.Builder() .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory .createMailtrapClient(config); long inboxId = 12345L; var updateRequest = new UpdateInboxRequest( new UpdateInboxRequest.InboxUpdateData("Updated Inbox Name", "new-username") ); var updatedInbox = client.testingApi().inboxes() .updateInbox(accountId, inboxId, updateRequest); System.out.println(updatedInbox); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } sandbox, _, err := client.Sandboxes.Update(context.Background(), 3000001, &mailtrap.SandboxUpdateRequest{ Name: "Renamed inbox", EmailUsername: "staging", }) if err != nil { log.Fatal(err) } fmt.Printf("updated sandbox %d: %s\n", sandbox.ID, sandbox.Name) } operationId: updateSandbox parameters: - $ref: '#/components/parameters/sandbox_id' '/api/sandboxes/{sandbox_id}/clean': patch: summary: Clean sandbox description: Delete all messages (emails) from sandbox. tags: - Sandboxes responses: '200': $ref: '#/components/responses/SandboxResponse' '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': $ref: '#/components/responses/PERMISSION_DENIED' '404': $ref: '#/components/responses/NOT_FOUND' x-codeSamples: - lang: shell label: 'cURL' source: | curl -X PATCH https://mailtrap.io/api/sandboxes/{sandbox_id}/clean \ -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | const { MailtrapClient } = require("mailtrap"); const TOKEN = "YOUR_API_KEY"; const ACCOUNT_ID = "YOUR_ACCOUNT_ID"; const client = new MailtrapClient({ token: TOKEN, accountId: ACCOUNT_ID }); async function cleanInbox() { const inboxId = 12345; const result = await client.testing.inboxes.clean(inboxId); console.log(result); } cleanInbox(); - lang: php label: PHP source: | inboxes($accountId); $inboxId = $_ENV['MAILTRAP_INBOX_ID']; $response = $sandboxInboxes->clean($inboxId); var_dump(ResponseHelper::toArray($response)); - lang: python label: Python source: | import mailtrap as mt API_TOKEN = "YOUR_API_KEY" ACCOUNT_ID = "YOUR_ACCOUNT_ID" client = mt.MailtrapClient(token=API_TOKEN, account_id=ACCOUNT_ID) inboxes_api = client.testing_api.inboxes inbox_id = 12345 result = inboxes_api.clean(inbox_id) print(result) - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: ENV['MAILTRAP_API_KEY']) inboxes = Mailtrap::InboxesAPI.new(YOUR_ACCOUNT_ID, client) inboxes.clean(INBOX_ID) - lang: csharp label: .NET source: | using Mailtrap; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var inboxId = 12345; var cleanedInbox = await client .Account(YOUR_ACCOUNT_ID) .Inbox(inboxId) .Clean(); Console.WriteLine(cleanedInbox); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; var config = new MailtrapConfig.Builder() .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory .createMailtrapClient(config); long inboxId = 12345L; var cleanedInbox = client.testingApi().inboxes() .cleanInbox(accountId, inboxId); System.out.println(cleanedInbox); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } sandbox, _, err := client.Sandboxes.Clean(context.Background(), 3000001) if err != nil { log.Fatal(err) } fmt.Printf("sandbox %d now holds %d message(s)\n", sandbox.ID, sandbox.EmailsCount) } operationId: cleanSandbox parameters: - $ref: '#/components/parameters/sandbox_id' '/api/sandboxes/{sandbox_id}/all_read': patch: summary: Mark as read description: Mark all messages in the sandbox as read. tags: - Sandboxes responses: '200': $ref: '#/components/responses/SandboxResponse' '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': $ref: '#/components/responses/PERMISSION_DENIED' '404': $ref: '#/components/responses/NOT_FOUND' x-codeSamples: - lang: shell label: 'cURL' source: | curl -X PATCH https://mailtrap.io/api/sandboxes/{sandbox_id}/all_read \ -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | const { MailtrapClient } = require("mailtrap"); const TOKEN = "YOUR_API_KEY"; const ACCOUNT_ID = "YOUR_ACCOUNT_ID"; const client = new MailtrapClient({ token: TOKEN, accountId: ACCOUNT_ID }); async function markAsRead() { const inboxId = 12345; const result = await client.testing.inboxes.markAsRead(inboxId); console.log(result); } markAsRead(); - lang: php label: PHP source: | inboxes($accountId); $inboxId = $_ENV['MAILTRAP_INBOX_ID']; $response = $sandboxInboxes->markAsRead($inboxId); var_dump(ResponseHelper::toArray($response)); - lang: python label: Python source: | import mailtrap as mt API_TOKEN = "YOUR_API_KEY" ACCOUNT_ID = "YOUR_ACCOUNT_ID" client = mt.MailtrapClient(token=API_TOKEN, account_id=ACCOUNT_ID) inboxes_api = client.testing_api.inboxes inbox_id = 12345 result = inboxes_api.mark_as_read(inbox_id) print(result) - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: ENV['MAILTRAP_API_KEY']) inboxes = Mailtrap::InboxesAPI.new(YOUR_ACCOUNT_ID, client) inboxes.mark_as_read(INBOX_ID) - lang: csharp label: .NET source: | using Mailtrap; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var inboxId = 12345; var markedInbox = await client .Account(YOUR_ACCOUNT_ID) .Inbox(inboxId) .MarkAsRead(); Console.WriteLine(markedInbox); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; var config = new MailtrapConfig.Builder() .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory .createMailtrapClient(config); long inboxId = 12345L; var markedInbox = client.testingApi().inboxes() .markAsRead(accountId, inboxId); System.out.println(markedInbox); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } sandbox, _, err := client.Sandboxes.MarkAllRead(context.Background(), 3000001) if err != nil { log.Fatal(err) } fmt.Printf("sandbox %d has %d unread message(s)\n", sandbox.ID, sandbox.EmailsUnreadCount) } operationId: markAsReadSandbox parameters: - $ref: '#/components/parameters/sandbox_id' '/api/sandboxes/{sandbox_id}/reset_credentials': patch: summary: Reset credentials description: Reset SMTP credentials of the sandbox. tags: - Sandboxes responses: '200': $ref: '#/components/responses/SandboxResponse' '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': $ref: '#/components/responses/PERMISSION_DENIED' '404': $ref: '#/components/responses/NOT_FOUND' x-codeSamples: - lang: shell label: 'cURL' source: | curl -X PATCH https://mailtrap.io/api/sandboxes/{sandbox_id}/reset_credentials \ -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | const { MailtrapClient } = require("mailtrap"); const TOKEN = "YOUR_API_KEY"; const ACCOUNT_ID = "YOUR_ACCOUNT_ID"; const client = new MailtrapClient({ token: TOKEN, accountId: ACCOUNT_ID }); async function resetCredentials() { const inboxId = 12345; const result = await client.testing.inboxes.resetCredentials(inboxId); console.log(result); } resetCredentials(); - lang: php label: PHP source: | inboxes($accountId); $inboxId = $_ENV['MAILTRAP_INBOX_ID']; $response = $sandboxInboxes->resetSmtpCredentials($inboxId); var_dump(ResponseHelper::toArray($response)); - lang: python label: Python source: | import mailtrap as mt API_TOKEN = "YOUR_API_KEY" ACCOUNT_ID = "YOUR_ACCOUNT_ID" client = mt.MailtrapClient(token=API_TOKEN, account_id=ACCOUNT_ID) inboxes_api = client.testing_api.inboxes inbox_id = 12345 result = inboxes_api.reset_credentials(inbox_id) print(result) - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: ENV['MAILTRAP_API_KEY']) inboxes = Mailtrap::InboxesAPI.new(YOUR_ACCOUNT_ID, client) inboxes.reset_credentials(INBOX_ID) - lang: csharp label: .NET source: | using Mailtrap; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var inboxId = 12345; var updatedInbox = await client .Account(YOUR_ACCOUNT_ID) .Inbox(inboxId) .ResetCredentials(); Console.WriteLine(updatedInbox); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; var config = new MailtrapConfig.Builder() .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory .createMailtrapClient(config); long inboxId = 12345L; var updatedInbox = client.testingApi().inboxes() .resetCredentials(accountId, inboxId); System.out.println(updatedInbox); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } sandbox, _, err := client.Sandboxes.ResetCredentials(context.Background(), 3000001) if err != nil { log.Fatal(err) } fmt.Printf("new SMTP credentials: %s / %s\n", sandbox.Username, sandbox.Password) } operationId: resetSandboxCredentials parameters: - $ref: '#/components/parameters/sandbox_id' '/api/sandboxes/{sandbox_id}/toggle_email_username': patch: summary: Enable email address description: Turn the email address of the sandbox on/off. tags: - Sandboxes responses: '200': $ref: '#/components/responses/SandboxResponse' '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': $ref: '#/components/responses/PERMISSION_DENIED' '404': $ref: '#/components/responses/NOT_FOUND' x-codeSamples: - lang: shell label: 'cURL' source: | curl -X PATCH https://mailtrap.io/api/sandboxes/{sandbox_id}/toggle_email_username \ -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | const { MailtrapClient } = require("mailtrap"); const TOKEN = "YOUR_API_KEY"; const ACCOUNT_ID = "YOUR_ACCOUNT_ID"; const client = new MailtrapClient({ token: TOKEN, accountId: ACCOUNT_ID }); async function enableEmailAddress() { const inboxId = 12345; const result = await client.testing.inboxes.enableEmailAddress(inboxId); console.log(result); } enableEmailAddress(); - lang: php label: PHP source: | inboxes($accountId); $inboxId = $_ENV['MAILTRAP_INBOX_ID']; $response = $sandboxInboxes->toggleEmailAddress($inboxId); var_dump(ResponseHelper::toArray($response)); - lang: python label: Python source: | import mailtrap as mt API_TOKEN = "YOUR_API_KEY" ACCOUNT_ID = "YOUR_ACCOUNT_ID" client = mt.MailtrapClient(token=API_TOKEN, account_id=ACCOUNT_ID) inboxes_api = client.testing_api.inboxes inbox_id = 12345 result = inboxes_api.enable_email_address(inbox_id) print(result) - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') account_id = 1000001 inboxes = Mailtrap::InboxesAPI.new(account_id, client) inbox_id = 12345 puts inboxes.toggle_email_username(inbox_id) - lang: csharp label: .NET source: | using Mailtrap; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var inboxId = 12345; var updatedInbox = await client .Account(YOUR_ACCOUNT_ID) .Inbox(inboxId) .ToggleEmailAddress(); Console.WriteLine(updatedInbox); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; var config = new MailtrapConfig.Builder() .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory .createMailtrapClient(config); long inboxId = 12345L; var updatedInbox = client.testingApi().inboxes() .enableEmailAddress(accountId, inboxId); System.out.println(updatedInbox); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } sandbox, _, err := client.Sandboxes.ToggleEmailAddress(context.Background(), 3000001) if err != nil { log.Fatal(err) } fmt.Printf("email address enabled: %t (%s@%s)\n", sandbox.EmailUsernameEnabled, sandbox.EmailUsername, sandbox.EmailDomain) } operationId: enableSandboxEmailAddresses parameters: - $ref: '#/components/parameters/sandbox_id' '/api/sandboxes/{sandbox_id}/reset_email_username': patch: summary: Reset email address description: Reset username of email address per sandbox. tags: - Sandboxes responses: '200': $ref: '#/components/responses/SandboxResponse' '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': $ref: '#/components/responses/PERMISSION_DENIED' '404': $ref: '#/components/responses/NOT_FOUND' x-codeSamples: - lang: shell label: 'cURL' source: | curl -X PATCH https://mailtrap.io/api/sandboxes/{sandbox_id}/reset_email_username \ -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | const { MailtrapClient } = require("mailtrap"); const TOKEN = "YOUR_API_KEY"; const ACCOUNT_ID = "YOUR_ACCOUNT_ID"; const client = new MailtrapClient({ token: TOKEN, accountId: ACCOUNT_ID }); async function resetEmailAddress() { const inboxId = 12345; const result = await client.testing.inboxes.resetEmailAddress(inboxId); console.log(result); } resetEmailAddress(); - lang: php label: PHP source: | inboxes($accountId); $inboxId = $_ENV['MAILTRAP_INBOX_ID']; $response = $sandboxInboxes->resetEmailAddress($inboxId); var_dump(ResponseHelper::toArray($response)); - lang: python label: Python source: | import mailtrap as mt API_TOKEN = "YOUR_API_KEY" ACCOUNT_ID = "YOUR_ACCOUNT_ID" client = mt.MailtrapClient(token=API_TOKEN, account_id=ACCOUNT_ID) inboxes_api = client.testing_api.inboxes inbox_id = 12345 result = inboxes_api.reset_email_username(inbox_id) print(result) - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: 'YOUR_API_KEY') account_id = 1000001 inboxes = Mailtrap::InboxesAPI.new(account_id, client) inbox_id = 12345 puts inboxes.reset_email_username(inbox_id) - lang: csharp label: .NET source: | using Mailtrap; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var inboxId = 12345; var updatedInbox = await client .Account(YOUR_ACCOUNT_ID) .Inbox(inboxId) .ResetEmailAddress(); Console.WriteLine(updatedInbox); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; var config = new MailtrapConfig.Builder() .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory .createMailtrapClient(config); long inboxId = 12345L; var updatedInbox = client.testingApi().inboxes() .resetEmailAddresses(accountId, inboxId); System.out.println(updatedInbox); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } sandbox, _, err := client.Sandboxes.ResetEmailAddress(context.Background(), 3000001) if err != nil { log.Fatal(err) } fmt.Printf("email address reset to %s@%s\n", sandbox.EmailUsername, sandbox.EmailDomain) } operationId: resetEmailUserNamePerSandbox parameters: - $ref: '#/components/parameters/sandbox_id' '/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' example: 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 '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': description: Returns forbidden error message. Check your permissions. content: application/json: schema: type: object properties: errors: type: string example: Account access forbidden '404': $ref: '#/components/responses/NOT_FOUND' x-codeSamples: - lang: shell label: 'cURL' source: | curl -X GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id} \ -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | const { MailtrapClient } = require("mailtrap"); const TOKEN = "YOUR_API_KEY"; const ACCOUNT_ID = "YOUR_ACCOUNT_ID"; const client = new MailtrapClient({ token: TOKEN, accountId: ACCOUNT_ID }); async function showMessage() { const inboxId = 12345; const messageId = 67890; const message = await client.testing.messages.showEmailMessage(inboxId, messageId); console.log(message); } showMessage(); - lang: php label: PHP source: | messages($accountId, $inboxId); $messageId = $_ENV['MAILTRAP_MESSAGE_ID']; $response = $sandboxMessages->getById($messageId); var_dump(ResponseHelper::toArray($response)); - lang: python label: Python source: | import mailtrap as mt API_TOKEN = "YOUR_API_KEY" ACCOUNT_ID = "YOUR_ACCOUNT_ID" client = mt.MailtrapClient(token=API_TOKEN, account_id=ACCOUNT_ID) messages_api = client.testing_api.messages inbox_id = 12345 message_id = 67890 message = messages_api.show_message(inbox_id=inbox_id, message_id=message_id) print(message) - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: ENV['MAILTRAP_API_KEY']) messages = Mailtrap::SandboxMessagesAPI.new(YOUR_ACCOUNT_ID, INBOX_ID, client) message = messages.get(MESSAGE_ID) puts message - lang: csharp label: .NET source: | using Mailtrap; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var inboxId = 54321; var messageId = 67890; var message = await client .Account(YOUR_ACCOUNT_ID) .Inbox(inboxId) .Message(messageId) .GetDetails(); Console.WriteLine(message); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; var config = new MailtrapConfig.Builder() .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory .createMailtrapClient(config); long inboxId = 12345L; long messageId = 67890L; var message = client.testingApi().messages() .getMessage(accountId, inboxId, messageId); System.out.println(message); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } message, _, err := client.SandboxMessages.Get(context.Background(), 3000001, 4000001) if err != nil { log.Fatal(err) } fmt.Printf("%s -> %s: %s (read: %t)\n", message.FromEmail, message.ToEmail, message.Subject, message.IsRead) } operationId: showSandboxEmailMessage 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 example: message: is_read: 'false' 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 example: 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 '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': description: Returns forbidden error message. Check your permissions. content: application/json: schema: type: object properties: errors: type: string example: Sandbox is not active or you have insufficient permissions '404': $ref: '#/components/responses/NOT_FOUND' x-codeSamples: - lang: shell label: 'cURL' source: | 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"}}' - lang: javascript label: Node.js source: | const { MailtrapClient } = require("mailtrap"); const TOKEN = "YOUR_API_KEY"; const ACCOUNT_ID = "YOUR_ACCOUNT_ID"; const client = new MailtrapClient({ token: TOKEN, accountId: ACCOUNT_ID }); const inboxId = 12345; const messageId = 67890; async function updateMessage() { const inboxId = 12345; const messageId = 67890; const updatedMessage = await client.testing.messages.updateMessage( inboxId, messageId, { isRead: true } ); console.log(updatedMessage); } updateMessage(); - lang: php label: PHP source: | messages($accountId, $inboxId); $messageId = $_ENV['MAILTRAP_MESSAGE_ID']; $response = $sandboxMessages->markAsRead($messageId); var_dump(ResponseHelper::toArray($response)); - lang: python label: Python source: | import mailtrap as mt API_TOKEN = "YOUR_API_KEY" ACCOUNT_ID = "YOUR_ACCOUNT_ID" client = mt.MailtrapClient(token=API_TOKEN, account_id=ACCOUNT_ID) messages_api = client.testing_api.messages inbox_id = 12345 message_id = 67890 updated_message = messages_api.update( inbox_id=inbox_id, message_id=message_id, message_params=mt.UpdateEmailMessageParams(is_read=True) ) print(updated_message) - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: ENV['MAILTRAP_API_KEY']) messages = Mailtrap::SandboxMessagesAPI.new(YOUR_ACCOUNT_ID, INBOX_ID, client) messages.mark_as_read(MESSAGE_ID) - lang: csharp label: .NET source: | using Mailtrap; using Mailtrap.TestingMessages.Requests; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var inboxId = 54321; var messageId = 67890; var updateRequest = new UpdateTestingMessageRequest(true); var updatedMessage = await client .Account(YOUR_ACCOUNT_ID) .Inbox(inboxId) .Message(messageId) .Update(updateRequest); Console.WriteLine(updatedMessage); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; import io.mailtrap.model.request.messages.UpdateMessageRequest; var config = new MailtrapConfig.Builder() .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory .createMailtrapClient(config); long inboxId = 12345L; long messageId = 67890L; var updateRequest = new UpdateMessageRequest( new UpdateMessageRequest.MessageUpdateData("true") ); var updatedMessage = client.testingApi().messages() .updateMessage(accountId, inboxId, messageId, updateRequest); System.out.println(updatedMessage); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } message, _, err := client.SandboxMessages.Update(context.Background(), 3000001, 4000001, true) if err != nil { log.Fatal(err) } fmt.Printf("message %d read: %t\n", message.ID, message.IsRead) } operationId: updateSandboxEmailMessage 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 example: 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 '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': $ref: '#/components/responses/PERMISSION_DENIED' '404': $ref: '#/components/responses/NOT_FOUND' x-codeSamples: - lang: shell label: 'cURL' source: | curl -X DELETE https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id} \ -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | const { MailtrapClient } = require("mailtrap"); const TOKEN = "YOUR_API_KEY"; const ACCOUNT_ID = "YOUR_ACCOUNT_ID"; const client = new MailtrapClient({ token: TOKEN, accountId: ACCOUNT_ID }); const inboxId = 12345; const messageId = 67890; async function deleteMessage() { const inboxId = 12345; const messageId = 67890; const result = await client.testing.messages.deleteMessage(inboxId, messageId); console.log(result); } deleteMessage(); - lang: php label: PHP source: | messages($accountId, $inboxId); $messageId = $_ENV['MAILTRAP_MESSAGE_ID']; $response = $sandboxMessages->delete($messageId); var_dump($response->getStatusCode()); - lang: python label: Python source: | import mailtrap as mt API_TOKEN = "YOUR_API_KEY" ACCOUNT_ID = "YOUR_ACCOUNT_ID" client = mt.MailtrapClient(token=API_TOKEN, account_id=ACCOUNT_ID) messages_api = client.testing_api.messages inbox_id = 12345 message_id = 67890 result = messages_api.delete(inbox_id=inbox_id, message_id=message_id) print(result) - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: ENV['MAILTRAP_API_KEY']) messages = Mailtrap::SandboxMessagesAPI.new(YOUR_ACCOUNT_ID, INBOX_ID, client) messages.delete(MESSAGE_ID) - lang: csharp label: .NET source: | using Mailtrap; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var inboxId = 54321; var messageId = 67890; var deletedMessage = await client .Account(YOUR_ACCOUNT_ID) .Inbox(inboxId) .Message(messageId) .Delete(); Console.WriteLine(deletedMessage); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; var config = new MailtrapConfig.Builder() .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory .createMailtrapClient(config); long inboxId = 12345L; long messageId = 67890L; var deletedMessage = client.testingApi().messages() .deleteMessage(accountId, inboxId, messageId); System.out.println(deletedMessage); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } // Delete returns the message it removed. message, _, err := client.SandboxMessages.Delete(context.Background(), 3000001, 4000001) if err != nil { log.Fatal(err) } fmt.Printf("deleted message %d (%s)\n", message.ID, message.Subject) } operationId: deleteSandboxEmailMessage parameters: - $ref: '#/components/parameters/sandbox_id' - $ref: '#/components/parameters/message_id' '/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' example: - 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 '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': description: Returns forbidden error message. Check your permissions. content: application/json: schema: type: object properties: errors: type: string example: Account access forbidden operationId: getSandboxEmailMessage x-codeSamples: - lang: shell label: 'cURL' source: | curl -X GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages \ -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | import { MailtrapClient } from "mailtrap"; const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId: ACCOUNT_ID }); async function getMessages() { const inboxId = 12345; const messages = await client.testing.messages.get(inboxId); console.log(messages); } getMessages(); - lang: php label: PHP source: | messages($accountId, $inboxId); $response = $sandboxMessages->getList(); var_dump(ResponseHelper::toArray($response)); - lang: python label: Python source: | import mailtrap as mt client = mt.MailtrapClient( token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID" ) inbox_id = 12345 messages = client.testing_api.messages.get_list( inbox_id=inbox_id ) for message in messages: print(f"From: {message.from_email}") print(f"Subject: {message.subject}") print(f"Received: {message.created_at}") - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: ENV['MAILTRAP_API_KEY']) messages = Mailtrap::SandboxMessagesAPI.new(YOUR_ACCOUNT_ID, INBOX_ID, client) messages.list.each do |message| puts "From: #{message.from_email}" puts "Subject: #{message.subject}" end # With search and pagination puts messages.list(search: 'welcome') puts messages.list(page: 2) - lang: csharp label: .NET source: | using Mailtrap; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var inboxId = 54321; var messages = await client .Account(YOUR_ACCOUNT_ID) .Inbox(inboxId) .Messages() .Fetch(); foreach (var message in messages) { Console.WriteLine($"From: {message.FromEmail}"); Console.WriteLine($"Subject: {message.Subject}"); Console.WriteLine($"Received: {message.CreatedAt}"); } - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; var config = new MailtrapConfig.Builder() .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory .createMailtrapClient(config); long inboxId = 12345L; var messages = client.testingApi().messages() .getMessages(accountId, inboxId); for (var message : messages) { System.out.println("From: " + message.getFromEmail()); System.out.println("Subject: " + message.getSubject()); System.out.println("Received: " + message.getCreatedAt()); } - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } messages, _, err := client.SandboxMessages.List(context.Background(), 3000001, &mailtrap.MessageListOptions{ Search: "welcome", Page: 1, }) if err != nil { log.Fatal(err) } for _, message := range messages { fmt.Printf("%d %s (from %s)\n", message.ID, message.Subject, message.FromEmail) } // To walk every page instead of one, use the iterator: // // for message, err := range client.SandboxMessages.All(context.Background(), 3000001, nil) { // if err != nil { // log.Fatal(err) // } // fmt.Println(message.Subject) // } } parameters: - schema: type: string example: welcome in: query name: search description: 'Search query string. Matches `subject`, `to_email`, and `to_name`.' - schema: type: number example: 123 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 example: 5 minimum: 1 in: query name: page description: Page number for paginated results. parameters: - $ref: '#/components/parameters/sandbox_id' '/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 example: jack@mailtrap.io responses: '200': description: Returns confirmation about forwarding. content: application/json: schema: type: object properties: message: type: string example: message: Your email message has been successfully forwarded '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': description: Returns forbidden error message. Check your permissions. content: application/json: schema: type: object properties: errors: type: string example: Account access forbidden '404': $ref: '#/components/responses/NOT_FOUND' x-codeSamples: - lang: shell label: 'cURL' source: | 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"}' - lang: javascript label: Node.js source: | const { MailtrapClient } = require("mailtrap"); const TOKEN = "YOUR_API_KEY"; const ACCOUNT_ID = "YOUR_ACCOUNT_ID"; const client = new MailtrapClient({ token: TOKEN, accountId: ACCOUNT_ID }); const inboxId = 12345; const messageId = 67890; async function forwardMessage() { const inboxId = 12345; const messageId = 67890; const result = await client.testing.messages.forward( inboxId, messageId, 'recipient@example.com' ); console.log(result); } forwardMessage(); - lang: php label: PHP source: | messages($accountId, $inboxId); $messageId = $_ENV['MAILTRAP_MESSAGE_ID']; $response = $sandboxMessages->forward($messageId, 'recipient@example.com'); var_dump(ResponseHelper::toArray($response)); - lang: python label: Python source: | import mailtrap as mt API_TOKEN = "YOUR_API_KEY" ACCOUNT_ID = "YOUR_ACCOUNT_ID" client = mt.MailtrapClient(token=API_TOKEN, account_id=ACCOUNT_ID) messages_api = client.testing_api.messages inbox_id = 12345 message_id = 67890 result = messages_api.forward( inbox_id=inbox_id, message_id=message_id, email="recipient@example.com" ) print(result) - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: ENV['MAILTRAP_API_KEY']) messages = Mailtrap::SandboxMessagesAPI.new(YOUR_ACCOUNT_ID, INBOX_ID, client) puts messages.forward_message(MESSAGE_ID, email: 'recipient@example.com') - lang: csharp label: .NET source: | using Mailtrap; using Mailtrap.TestingMessages.Requests; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var inboxId = 54321; var messageId = 67890; var forwardRequest = new ForwardTestingMessageRequest("recipient@example.com"); var forwardedMessage = await client .Account(YOUR_ACCOUNT_ID) .Inbox(inboxId) .Message(messageId) .Forward(forwardRequest); Console.WriteLine(forwardedMessage); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; import io.mailtrap.model.request.messages.ForwardMessageRequest; var config = new MailtrapConfig.Builder() .token("YOUR_API_KEY") .build(); var client = MailtrapClientFactory .createMailtrapClient(config); long inboxId = 12345L; long messageId = 67890L; var forwardRequest = new ForwardMessageRequest("recipient@example.com"); var forwardedMessage = client.testingApi().messages() .forwardMessage(accountId, inboxId, messageId, forwardRequest); System.out.println(forwardedMessage); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } // The recipient must have confirmed forwarding to this address in advance. if _, err := client.SandboxMessages.Forward(context.Background(), 3000001, 4000001, "qa@example.com"); err != nil { log.Fatal(err) } fmt.Println("message forwarded") } operationId: forwardSandboxEmailMessage parameters: - $ref: '#/components/parameters/sandbox_id' - $ref: '#/components/parameters/message_id' '/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 example: 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' '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': description: Returns forbidden error message. Check your permissions. content: application/json: schema: type: object properties: errors: type: string example: Account access forbidden '404': $ref: '#/components/responses/NOT_FOUND' x-codeSamples: - lang: shell label: 'cURL' source: | curl -X GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id}/spam_report \ -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | const { MailtrapClient } = require("mailtrap"); const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId: "YOUR_ACCOUNT_ID" }); async function getSpamScore() { const spamReport = await client.testing.messages.getSpamScore(12345, 67890); console.log(spamReport); } getSpamScore(); - lang: php label: PHP source: | messages($accountId, $inboxId); $messageId = $_ENV['MAILTRAP_MESSAGE_ID']; $response = $sandboxMessages->getSpamScore($messageId); var_dump(ResponseHelper::toArray($response)); - lang: python label: Python source: | import mailtrap as mt client = mt.MailtrapClient(token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID") spam_report = client.testing_api.messages.get_spam_report(inbox_id=12345, message_id=67890) print(spam_report) - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: ENV['MAILTRAP_API_KEY']) messages = Mailtrap::SandboxMessagesAPI.new(YOUR_ACCOUNT_ID, INBOX_ID, client) puts messages.spam_score(MESSAGE_ID) - lang: csharp label: .NET source: | using Mailtrap; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var inboxId = 54321; var messageId = 67890; var spamReport = await client .Account(YOUR_ACCOUNT_ID) .Inbox(inboxId) .Message(messageId) .GetSpamReport(); Console.WriteLine(spamReport); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); var client = MailtrapClientFactory.createMailtrapClient(config); long inboxId = 12345L; long messageId = 67890L; var spamReport = client.testingApi().messages().getSpamScore(accountId, inboxId, messageId); System.out.println(spamReport); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } report, _, err := client.SandboxMessages.SpamReport(context.Background(), 3000001, 4000001) if err != nil { log.Fatal(err) } fmt.Printf("score %.2f of %.2f, spam: %t\n", report.Score, report.Threshold, report.Spam) for _, detail := range report.Details { fmt.Printf(" %+.2f %s: %s\n", detail.Pts, detail.RuleName, detail.Description) } } operationId: getSandboxEmailMessageSpamReport parameters: - $ref: '#/components/parameters/sandbox_id' - $ref: '#/components/parameters/message_id' '/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 example: 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 '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': description: Returns forbidden error message. Check your permissions. content: application/json: schema: type: object properties: errors: type: string example: Account access forbidden '404': $ref: '#/components/responses/NOT_FOUND' x-codeSamples: - lang: shell label: 'cURL' source: | curl -X GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id}/analyze \ -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | const { MailtrapClient } = require("mailtrap"); const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId: "YOUR_ACCOUNT_ID" }); async function getHtmlAnalysis() { const htmlAnalysis = await client.testing.messages.getHtmlAnalysis(12345, 67890); console.log(htmlAnalysis); } getHtmlAnalysis(); - lang: php label: PHP source: | messages($accountId, $inboxId); $messageId = $_ENV['MAILTRAP_MESSAGE_ID']; $response = $sandboxMessages->getHtmlAnalysis($messageId); var_dump(ResponseHelper::toArray($response)); - lang: python label: Python source: | import mailtrap as mt client = mt.MailtrapClient(token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID") html_analysis = client.testing_api.messages.get_html_analysis(inbox_id=12345, message_id=67890) print(html_analysis) - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: ENV['MAILTRAP_API_KEY']) messages = Mailtrap::SandboxMessagesAPI.new(YOUR_ACCOUNT_ID, INBOX_ID, client) puts messages.html_analysis(MESSAGE_ID) - lang: csharp label: .NET source: | using Mailtrap; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var inboxId = 54321; var messageId = 67890; var htmlReport = await client .Account(YOUR_ACCOUNT_ID) .Inbox(inboxId) .Message(messageId) .GetHtmlAnalysisReport(); Console.WriteLine(htmlReport); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); var client = MailtrapClientFactory.createMailtrapClient(config); long inboxId = 12345L; var htmlAnalysis = client.testingApi().messages().getMessageHtmlAnalysis(accountId, inboxId, messageId); System.out.println(htmlAnalysis); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } report, _, err := client.SandboxMessages.HTMLAnalysis(context.Background(), 3000001, 4000001) if err != nil { log.Fatal(err) } for _, issue := range report.Errors { fmt.Printf("line %d: %s (desktop: %v)\n", issue.ErrorLine, issue.RuleName, issue.EmailClients.Desktop) } } operationId: getSandboxEmailMessageHTMLAnalysis parameters: - $ref: '#/components/parameters/sandbox_id' - $ref: '#/components/parameters/message_id' '/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 example: | 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. '401': description: Returns unauthorized error message. Check your credentials. content: text/plain: schema: type: string example: '{"error":"Incorrect API token"}' '403': description: Returns forbidden error message. Check your permissions. content: text/plain: schema: type: string example: '{:errors=>"Account access forbidden"}' '404': $ref: '#/components/responses/NOT_FOUND' '409': description: Returns conflict error message. Text body does not exist. content: text/plain: schema: type: string example: Conflict x-codeSamples: - lang: shell label: 'cURL' source: | curl -X GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id}/body.txt \ -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | const { MailtrapClient } = require("mailtrap"); const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId: "YOUR_ACCOUNT_ID" }); async function getTextMessage() { const textBody = await client.testing.messages.getTextMessage(12345, 67890); console.log(textBody); } getTextMessage(); - lang: php label: PHP source: | messages($accountId, $inboxId); $messageId = $_ENV['MAILTRAP_MESSAGE_ID']; $textBody = ResponseHelper::toString( $sandboxMessages->getText($messageId) ); var_dump($textBody); - lang: python label: Python source: | import mailtrap as mt client = mt.MailtrapClient(token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID") text_body = client.testing_api.messages.get_text_message(inbox_id=12345, message_id=67890) print(text_body) - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: ENV['MAILTRAP_API_KEY']) messages = Mailtrap::SandboxMessagesAPI.new(YOUR_ACCOUNT_ID, INBOX_ID, client) puts messages.text_body(MESSAGE_ID) - lang: csharp label: .NET source: | using Mailtrap; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var inboxId = 54321; var messageId = 67890; var textBody = await client .Account(YOUR_ACCOUNT_ID) .Inbox(inboxId) .Message(messageId) .GetTextBody(); Console.WriteLine(textBody); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); var client = MailtrapClientFactory.createMailtrapClient(config); long inboxId = 12345L; long messageId = 67890L; String textBody = client.testingApi().messages().getTextMessage(accountId, inboxId, messageId); System.out.println(textBody); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } // The body endpoints return the raw bytes. body, _, err := client.SandboxMessages.Text(context.Background(), 3000001, 4000001) if err != nil { log.Fatal(err) } // body holds the plain-text body. fmt.Println(string(body)) } operationId: getSandboxEmailMessageBodyAsTxt parameters: - $ref: '#/components/parameters/sandbox_id' - $ref: '#/components/parameters/message_id' '/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 example: | From: Magic Elves To: Mailtrap Inbox 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

Congrats for sending test email with Mailtrap!

Inspect it using the tabs you see above and learn how this email can be improved.

Inspect with Tabs

Now send your email using our fake SMTP server and integration of your choice!

Good luck! Hope it works.

--boundary-string-- '401': description: Returns unauthorized error message. Check your credentials. content: text/plain: schema: type: string example: '{"error":"Incorrect API token"}' '403': description: Returns forbidden error message. Check your permissions. content: text/plain: schema: type: string example: '{:errors=>"Account access forbidden"}' '404': $ref: '#/components/responses/NOT_FOUND' '409': description: Returns conflict error message. Raw body does not exist. content: text/plain: schema: type: string example: Conflict x-codeSamples: - lang: shell label: 'cURL' source: | curl -X GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id}/body.raw \ -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | const { MailtrapClient } = require("mailtrap"); const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId: "YOUR_ACCOUNT_ID" }); async function getRawMessage() { const rawBody = await client.testing.messages.getRawMessage(12345, 67890); console.log(rawBody); } getRawMessage(); - lang: php label: PHP source: | messages($accountId, $inboxId); $messageId = $_ENV['MAILTRAP_MESSAGE_ID']; $rawBody = ResponseHelper::toString( $sandboxMessages->getRaw($messageId) ); var_dump($rawBody); - lang: python label: Python source: | import mailtrap as mt client = mt.MailtrapClient(token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID") raw_body = client.testing_api.messages.get_raw_message(inbox_id=12345, message_id=67890) print(raw_body) - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: ENV['MAILTRAP_API_KEY']) messages = Mailtrap::SandboxMessagesAPI.new(YOUR_ACCOUNT_ID, INBOX_ID, client) puts messages.raw_body(MESSAGE_ID) - lang: csharp label: .NET source: | using Mailtrap; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var inboxId = 54321; var messageId = 67890; var rawBody = await client .Account(YOUR_ACCOUNT_ID) .Inbox(inboxId) .Message(messageId) .AsRaw(); Console.WriteLine(rawBody); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); var client = MailtrapClientFactory.createMailtrapClient(config); long inboxId = 12345L; long messageId = 67890L; String rawBody = client.testingApi().messages().getRawMessage(accountId, inboxId, messageId); System.out.println(rawBody); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } // The body endpoints return the raw bytes. body, _, err := client.SandboxMessages.Raw(context.Background(), 3000001, 4000001) if err != nil { log.Fatal(err) } // body holds the raw MIME source. fmt.Println(string(body)) } operationId: getSandboxEmailMessageBodyAsRaw parameters: - $ref: '#/components/parameters/sandbox_id' - $ref: '#/components/parameters/message_id' '/api/sandboxes/{sandbox_id}/messages/{message_id}/body.htmlsource': get: summary: Get message source description: Get the HTML body of an email as it was sent. Not applicable for plain text emails. tags: - Messages responses: '200': description: Returns the HTML body as it was sent. content: text/html: schema: type: string example: |

Congrats for sending test email with Mailtrap!

Inspect it using the tabs you see above and learn how this email can be improved.

Inspect with Tabs

Now send your email using our fake SMTP server and integration of your choice!

Confirm your email

Good luck! Hope it works.

'401': description: Returns unauthorized error message. Check your credentials. content: text/plain: schema: type: string example: '{"error":"Incorrect API token"}' '403': description: Returns forbidden error message. Check your permissions. content: text/plain: schema: type: string example: '{:errors=>"Account access forbidden"}' '404': $ref: '#/components/responses/NOT_FOUND' '409': description: Returns conflict error message. HTML source does not exist. content: text/plain: schema: type: string example: Conflict x-codeSamples: - lang: shell label: 'cURL' source: | curl -X GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id}/body.htmlsource \ -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | const { MailtrapClient } = require("mailtrap"); const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId: "YOUR_ACCOUNT_ID" }); async function getHtmlSource() { const htmlSource = await client.testing.messages.getMessageHtmlSource(12345, 67890); console.log(htmlSource); } getHtmlSource(); - lang: php label: PHP source: | messages($accountId, $inboxId); $messageId = $_ENV['MAILTRAP_MESSAGE_ID']; $response = $sandboxMessages->getSource($messageId); var_dump(ResponseHelper::toString($response)); - lang: python label: Python source: | import mailtrap as mt client = mt.MailtrapClient(token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID") html_source = client.testing_api.messages.get_html_source(inbox_id=12345, message_id=67890) print(html_source) - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: ENV['MAILTRAP_API_KEY']) messages = Mailtrap::SandboxMessagesAPI.new(YOUR_ACCOUNT_ID, INBOX_ID, client) puts messages.html_source(MESSAGE_ID) - lang: csharp label: .NET source: | using Mailtrap; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var inboxId = 54321; var messageId = 67890; var htmlSource = await client .Account(YOUR_ACCOUNT_ID) .Inbox(inboxId) .Message(messageId) .GetHtmlSource(); Console.WriteLine(htmlSource); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); var client = MailtrapClientFactory.createMailtrapClient(config); long inboxId = 12345L; long messageId = 67890L; String htmlSource = client.testingApi().messages().getMessageSource(accountId, inboxId, messageId); System.out.println(htmlSource); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } // The body endpoints return the raw bytes. body, _, err := client.SandboxMessages.HTMLSource(context.Background(), 3000001, 4000001) if err != nil { log.Fatal(err) } // body holds the HTML source. fmt.Println(string(body)) } operationId: getSandboxEmailMessageBodyAsHtmlSource parameters: - $ref: '#/components/parameters/sandbox_id' - $ref: '#/components/parameters/message_id' '/api/sandboxes/{sandbox_id}/messages/{message_id}/body.html': get: summary: Get HTML message description: | Get the HTML body of an email, sanitized for preview. Not applicable for plain text emails. The response is not the email as it was sent. Mailtrap changes it as follows: - The response is always a full HTML document with `html`, `head` and `body` elements. - The first element in `head` is a `` tag. - Entities such as `©` come back as the character (`©`). `&`, `<`, `>`, non-breaking spaces and quotes in attribute values stay escaped, so a raw `&` in a link URL comes back as `&`. - Scripts and stylesheet links are removed. Stylesheet links to Google Fonts stay. - Each `@import` rule in a ` '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': description: Returns forbidden error message. Check your permissions. content: application/json: schema: type: object properties: errors: type: string example: Account access forbidden '404': $ref: '#/components/responses/NOT_FOUND' '409': description: Returns conflict error message. HTML source does not exist. content: text/plain: schema: type: string example: Conflict '429': description: Mailtrap is sanitizing too many large HTML bodies at the same time. Retry after the number of seconds in `Retry-After`. headers: Retry-After: description: The number of seconds to wait before you retry. schema: type: integer example: 2 x-codeSamples: - lang: shell label: 'cURL' source: | curl -X GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id}/body.html \ -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | const { MailtrapClient } = require("mailtrap"); const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId: "YOUR_ACCOUNT_ID" }); const ACCOUNT_ID = "YOUR_ACCOUNT_ID"; async function getHtmlMessage() { const htmlBody = await client.testing.messages.getHtmlMessage(ACCOUNT_ID, 12345, 67890); console.log(htmlBody); } getHtmlMessage(); - lang: php label: PHP source: | messages($accountId, $inboxId); $messageId = $_ENV['MAILTRAP_MESSAGE_ID']; $htmlBody = ResponseHelper::toString( $sandboxMessages->getHtml($messageId) ); var_dump($htmlBody); - lang: python label: Python source: | import mailtrap as mt client = mt.MailtrapClient(token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID") html_body = client.testing_api.messages.get_html_message(inbox_id=12345, message_id=67890) print(html_body) - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: ENV['MAILTRAP_API_KEY']) messages = Mailtrap::SandboxMessagesAPI.new(YOUR_ACCOUNT_ID, INBOX_ID, client) puts messages.html_body(MESSAGE_ID) - lang: csharp label: .NET source: | using Mailtrap; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var inboxId = 54321; var messageId = 67890; var htmlBody = await client .Account(YOUR_ACCOUNT_ID) .Inbox(inboxId) .Message(messageId) .GetHtmlBody(); Console.WriteLine(htmlBody); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); var client = MailtrapClientFactory.createMailtrapClient(config); long inboxId = 12345L; long messageId = 12345L; String htmlBody = client.testingApi().messages().getHtmlMessage(accountId, inboxId, messageId); System.out.println(htmlBody); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } // The body endpoints return the raw bytes. body, _, err := client.SandboxMessages.HTML(context.Background(), 3000001, 4000001) if err != nil { log.Fatal(err) } // body holds the formatted HTML body. fmt.Println(string(body)) } operationId: getSandboxEmailMessageBodyAsHtml parameters: - $ref: '#/components/parameters/sandbox_id' - $ref: '#/components/parameters/message_id' '/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 example: | From: Magic Elves To: Mailtrap Inbox 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

Congrats for sending test email with Mailtrap!

Inspect it using the tabs you see above and learn how this email can be improved.

Inspect with Tabs

Now send your email using our fake SMTP server and integration of your choice!

Good luck! Hope it works.

--boundary-string-- '401': description: Returns unauthorized error message. Check your credentials. content: text/plain: schema: type: string example: '{"error":"Incorrect API token"}' '403': description: Returns forbidden error message. Check your permissions. content: text/plain: schema: type: string example: '{:errors=>"Account access forbidden"}' '404': $ref: '#/components/responses/NOT_FOUND' '409': description: Returns conflict error message. .eml body does not exist. content: text/plain: schema: type: string example: Conflict x-codeSamples: - lang: shell label: 'cURL' source: | curl -X GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id}/body.eml \ -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | const { MailtrapClient } = require("mailtrap"); const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId: "YOUR_ACCOUNT_ID" }); async function getMessageAsEml() { const emlContent = await client.testing.messages.getMessageAsEml(12345, 67890); console.log(emlContent); } getMessageAsEml(); - lang: php label: PHP source: | messages($accountId, $inboxId); $messageId = $_ENV['MAILTRAP_MESSAGE_ID']; $emlContent = ResponseHelper::toString( $sandboxMessages->getEml($messageId) ); var_dump($emlContent); - lang: python label: Python source: | import mailtrap as mt client = mt.MailtrapClient(token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID") eml_content = client.testing_api.messages.get_message_as_eml(inbox_id=12345, message_id=67890) print(eml_content) - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: ENV['MAILTRAP_API_KEY']) messages = Mailtrap::SandboxMessagesAPI.new(YOUR_ACCOUNT_ID, INBOX_ID, client) puts messages.eml_body(MESSAGE_ID) - lang: csharp label: .NET source: | using Mailtrap; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var inboxId = 54321; var messageId = 67890; var emlContent = await client .Account(YOUR_ACCOUNT_ID) .Inbox(inboxId) .Message(messageId) .AsEml(); Console.WriteLine(emlContent); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); var client = MailtrapClientFactory.createMailtrapClient(config); long inboxId = 12345L; long messageId = 67890L; String emlContent = client.testingApi().messages().getMessageAsEml(accountId, inboxId, messageId); System.out.println(emlContent); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } // The body endpoints return the raw bytes. body, _, err := client.SandboxMessages.EML(context.Background(), 3000001, 4000001) if err != nil { log.Fatal(err) } // body holds the message in .eml format. fmt.Println(string(body)) } operationId: getSandboxEmailMessageBodyAsEml parameters: - $ref: '#/components/parameters/sandbox_id' - $ref: '#/components/parameters/message_id' '/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: x-examples: Example 1: 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 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. examples: Example 1: value: 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 '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': $ref: '#/components/responses/PERMISSION_DENIED' '404': $ref: '#/components/responses/NOT_FOUND' x-codeSamples: - lang: shell label: 'cURL' source: | curl -X GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id}/mail_headers \ -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | const { MailtrapClient } = require("mailtrap"); const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId: "YOUR_ACCOUNT_ID" }); async function getMailHeaders() { const mailHeaders = await client.testing.messages.getMailHeaders(12345, 67890); console.log(mailHeaders); } getMailHeaders(); - lang: php label: PHP source: | messages($accountId, $inboxId); $messageId = $_ENV['MAILTRAP_MESSAGE_ID']; $mailHeaders = $sandboxMessages->getMailHeaders($messageId); var_dump(ResponseHelper::toArray($mailHeaders)); - lang: python label: Python source: | import mailtrap as mt client = mt.MailtrapClient(token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID") mail_headers = client.testing_api.messages.get_mail_headers(inbox_id=12345, message_id=67890) print(mail_headers) - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: ENV['MAILTRAP_API_KEY']) messages = Mailtrap::SandboxMessagesAPI.new(YOUR_ACCOUNT_ID, INBOX_ID, client) puts messages.mail_headers(MESSAGE_ID) - lang: csharp label: .NET source: | using Mailtrap; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var inboxId = 54321; var messageId = 67890; var mailHeaders = await client .Account(YOUR_ACCOUNT_ID) .Inbox(inboxId) .Message(messageId) .GetHeaders(); Console.WriteLine(mailHeaders.Headers); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; var config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); var client = MailtrapClientFactory.createMailtrapClient(config); long inboxId = 12345L; long messageId = 67890L; var mailHeaders = client.testingApi().messages().getMailHeaders(accountId, inboxId, messageId); System.out.println(mailHeaders); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } headers, _, err := client.SandboxMessages.Headers(context.Background(), 3000001, 4000001) if err != nil { log.Fatal(err) } for name, value := range headers { fmt.Printf("%s: %s\n", name, value) } } operationId: getMailHeadersOfEmailMessage parameters: - $ref: '#/components/parameters/sandbox_id' - $ref: '#/components/parameters/message_id' '/api/sandboxes/{sandbox_id}/messages/{message_id}/attachments': get: summary: Get attachments description: Get message attachments by sandbox_id and message_id. tags: - Attachments parameters: - name: attachment_type description: Attachment type in: query schema: type: string example: inline responses: '200': description: Lists attachments with their details and download paths. content: application/json: schema: type: array items: type: object properties: id: type: integer message_id: type: integer filename: type: string attachment_type: type: string content_type: type: string content_id: type: string nullable: true transfer_encoding: type: string nullable: true attachment_size: type: integer created_at: type: string updated_at: type: string attachment_human_size: type: string download_path: type: string example: - id: 67 message_id: 457 filename: test.csv attachment_type: inline content_type: plain/text content_id: null transfer_encoding: null attachment_size: 0 created_at: '2022-06-02T19:25:54.827Z' updated_at: '2022-06-02T19:25:54.827Z' attachment_human_size: 0 Bytes download_path: /api/accounts/3831/sandboxes/4394/messages/457/attachments/67/download '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': description: Returns forbidden error message. Check your permissions. content: application/json: schema: type: object properties: errors: type: string example: Account access forbidden '404': $ref: '#/components/responses/NOT_FOUND' operationId: getSandboxMessageAttachments x-codeSamples: - lang: shell label: 'cURL' source: | curl -X GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id}/attachments \ -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | const { MailtrapClient } = require("mailtrap"); const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId: "YOUR_ACCOUNT_ID" }); async function getAttachments() { const attachments = await client.testing.attachments.getList(67890, 12345); console.log(attachments); } getAttachments(); - lang: php label: PHP source: | attachments($accountId, $inboxId); $messageId = $_ENV['MAILTRAP_MESSAGE_ID']; $response = $sandboxAttachments->getMessageAttachments($messageId); var_dump(ResponseHelper::toArray($response)); - lang: python label: Python source: | import mailtrap as mt client = mt.MailtrapClient(token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID") attachments = client.testing_api.attachments.get_list(inbox_id=12345, message_id=67890) - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: ENV['MAILTRAP_API_KEY']) attachments = Mailtrap::SandboxAttachmentsAPI.new( YOUR_ACCOUNT_ID, INBOX_ID, MESSAGE_ID, client ) puts attachments.list - lang: csharp label: C# source: | using Mailtrap; using Mailtrap.Attachments; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var inboxId = 54321; var messageId = 67890; var attachments = await client .Account(YOUR_ACCOUNT_ID) .Inbox(inboxId) .Message(messageId) .Attachments() .Fetch(); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; MailtrapConfig config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); var client = MailtrapClientFactory.createMailtrapClient(config); long inboxId = 12345L; long messageId = 67890L; var attachments = client.testingApi().attachments().getAttachments(accountId, inboxId, messageId, null); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } attachments, _, err := client.SandboxAttachments.List(context.Background(), 3000001, 4000001, &mailtrap.AttachmentListOptions{ Type: "attachment", }) if err != nil { log.Fatal(err) } for _, attachment := range attachments { fmt.Printf("%d %s (%s, %s)\n", attachment.ID, attachment.Filename, attachment.ContentType, attachment.AttachmentHumanSize) } } parameters: - $ref: '#/components/parameters/sandbox_id' - $ref: '#/components/parameters/message_id' '/api/sandboxes/{sandbox_id}/messages/{message_id}/attachments/{attachment_id}': get: summary: Get single attachment description: Get message single attachment by id. tags: - Attachments responses: '200': description: Returns attachment details and download path. content: application/json: schema: type: object properties: id: type: integer message_id: type: integer filename: type: string attachment_type: type: string content_type: type: string content_id: type: string nullable: true transfer_encoding: type: string nullable: true attachment_size: type: integer created_at: type: string updated_at: type: string attachment_human_size: type: string download_path: type: string example: id: 70 message_id: 460 filename: test.csv attachment_type: inline content_type: plain/text content_id: null transfer_encoding: null attachment_size: 0 created_at: '2022-06-02T19:25:55.687Z' updated_at: '2022-06-02T19:25:55.687Z' attachment_human_size: 0 Bytes download_path: /api/accounts/3838/sandboxes/4401/messages/460/attachments/70/download '401': $ref: '#/components/responses/UNAUTHENTICATED' '403': description: Returns forbidden error message. Check your permissions. content: application/json: schema: type: object properties: errors: type: string example: Account access forbidden '404': $ref: '#/components/responses/NOT_FOUND' operationId: getSandboxMessageAttachment x-codeSamples: - lang: shell label: 'cURL' source: | curl -X GET https://mailtrap.io/api/sandboxes/{sandbox_id}/messages/{message_id}/attachments/{attachment_id} \ -H 'Authorization: Bearer YOUR_API_KEY' - lang: javascript label: Node.js source: | const { MailtrapClient } = require("mailtrap"); const client = new MailtrapClient({ token: "YOUR_API_KEY", accountId: "YOUR_ACCOUNT_ID" }); async function getAttachment() { const attachment = await client.testing.attachments.get(12345, 67890, 222222); console.log(attachment); } getAttachment(); - lang: php label: PHP source: | attachments($accountId, $inboxId); $messageId = $_ENV['MAILTRAP_MESSAGE_ID']; $attachmentId = $_ENV['MAILTRAP_MESSAGE_ATTACHMENT_ID']; $response = $sandboxAttachments->getMessageAttachment($messageId, $attachmentId); var_dump(ResponseHelper::toArray($response)); - lang: python label: Python source: | import mailtrap as mt client = mt.MailtrapClient(token="YOUR_API_KEY", account_id="YOUR_ACCOUNT_ID") attachment = client.testing_api.attachments.get(inbox_id=12345, message_id=67890, attachment_id=222222) - lang: ruby label: Ruby source: | require 'mailtrap' client = Mailtrap::Client.new(api_key: ENV['MAILTRAP_API_KEY']) attachments = Mailtrap::SandboxAttachmentsAPI.new( YOUR_ACCOUNT_ID, INBOX_ID, MESSAGE_ID, client ) puts "Attachment: #{attachments.get(ATTACHMENT_ID)}" - lang: csharp label: C# source: | using Mailtrap; using Mailtrap.Attachments; using var mailtrapFactory = new MailtrapClientFactory("YOUR_API_KEY"); var client = mailtrapFactory.CreateClient(); var inboxId = 54321; var messageId = 67890; var attachmentId = 222222; var attachment = await client .Account(YOUR_ACCOUNT_ID) .Inbox(inboxId) .Message(messageId) .Attachment(attachmentId) .GetDetails(); - lang: java label: Java source: | import io.mailtrap.config.MailtrapConfig; import io.mailtrap.factory.MailtrapClientFactory; MailtrapConfig config = new MailtrapConfig.Builder().token("YOUR_API_KEY").build(); long inboxId = 12345L; long messageId = 67890L; long attachmentId = 222222L; var client = MailtrapClientFactory.createMailtrapClient(config); var attachment = client.testingApi().attachments().getSingleAttachment(accountId, inboxId, messageId, attachmentId); - lang: go label: Go source: | package main import ( "context" "fmt" "log" "os" "github.com/mailtrap/mailtrap-go" ) func main() { client, err := mailtrap.NewClient(os.Getenv("MAILTRAP_API_TOKEN")) if err != nil { log.Fatal(err) } attachment, _, err := client.SandboxAttachments.Get(context.Background(), 3000001, 4000001, 5000001) if err != nil { log.Fatal(err) } fmt.Printf("%s (%s): %s\n", attachment.Filename, attachment.ContentType, attachment.DownloadPath) } parameters: - $ref: '#/components/parameters/sandbox_id' - $ref: '#/components/parameters/message_id' - $ref: '#/components/parameters/attachment_id' components: 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/...`. `blacklists_report_info` may contain only `result` or the full report. `template_variables` is set when the message was sent from a template. 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 Project: title: Testing Project type: object properties: id: type: integer name: type: string share_links: type: object properties: admin: type: string viewer: type: string sandboxes: type: array items: nullable: true $ref: '#/components/schemas/TestingSandbox' permissions: type: object properties: can_read: type: boolean can_update: type: boolean can_destroy: type: boolean can_leave: type: boolean example: id: 2388 name: My New Project share_links: admin: 'https://localhost/projects/2388/share/QEVuQwEAS-hQfYV1hqw15p7p9VcsuCrASDQUkcuV_N5G-zdVBPrd58V8Ce09AUl-JGFEJsQbt-K6IzRIMhjpU7zxAnIo9QpB8mJwuOqBiottfwdDhgKO-ab7t7WDCyyoGeG5dLK_' viewer: 'https://localhost/projects/2388/share/QEVuQwEAS-hQfYV1hqw15p7p9VcsuCrASDQUkcuV_N5G-zdVBPrd58V8Ce09AUl-JGFEJsQbHDFqI6Mk2wRVlVSxLNMgI-3LnWpSSSyCSbjqkQRAMPVoTPYF7WcXfw4H_CwkAc4e' sandboxes: [] permissions: can_read: true can_update: true can_destroy: true can_leave: false NotFoundResponse: title: NotFoundResponse type: object properties: error: type: string description: Error message example: Not Found example: error: Not Found PermissionsDeniedResponse: title: PermissionsDeniedResponse type: object properties: errors: type: string description: Error message example: Account access forbidden example: errors: Account access forbidden TestingSandbox: title: Testing Sandbox type: object properties: id: type: integer name: type: string username: type: string password: type: string nullable: true description: Password is only available if you have admin permissions for the sandbox. max_size: type: integer status: type: string enum: - active - inactive - pending email_username: type: string email_username_enabled: type: boolean sent_messages_count: type: integer forwarded_messages_count: type: integer used: type: boolean forward_from_email_address: type: string project_id: type: integer domain: type: string pop3_domain: type: string email_domain: type: string api_domain: type: string emails_count: type: integer emails_unread_count: type: integer last_message_sent_at: nullable: true type: string smtp_ports: type: array items: type: integer pop3_ports: type: array items: type: integer max_message_size: type: integer permissions: type: object properties: can_read: type: boolean can_update: type: boolean can_destroy: type: boolean can_leave: type: boolean example: id: 3538 name: Admin Sandbox username: b3a87978452ae1 password: 6be9fcfc613a7c max_size: 0 status: active email_username: b7eae548c3-54c542 email_username_enabled: false sent_messages_count: 52 forwarded_messages_count: 0 used: false forward_from_email_address: a3538-i4088@forward.mailtrap.info project_id: 2293 domain: localhost pop3_domain: localhost email_domain: localhost api_domain: localhost emails_count: 0 emails_unread_count: 0 last_message_sent_at: null smtp_ports: - 25 - 465 - 587 - 2525 pop3_ports: - 1100 - 9950 max_message_size: 5242880 permissions: can_read: true can_update: true can_destroy: true can_leave: true UnauthenticatedResponse: title: UnauthenticatedResponse type: object properties: error: type: string description: Error message example: Incorrect API token example: error: Incorrect API token examples: Projects: summary: List of projects value: - id: 2435 name: Viewer Project sandboxes: [] permissions: can_read: true can_update: false can_destroy: false can_leave: true - id: 2436 name: Admin Project share_links: admin: 'https://localhost/projects/2436/share/QEVuQwEAYWN-NIhmrB8qX6ZWzToqdOE9dw1ylIfOQ-_fKwYAD_CCkhRzmAanker219x25PM75TBaHgx1I4dsv058hghY_Ewaa3Vt7ET1aeg3ufVcit919V4baPLzxV9JaRzXWSjK' viewer: 'https://localhost/projects/2436/share/QEVuQwEAYWN-NIhmrB8qX6ZWzToqdOE9dw1ylIfOQ-_fKwYAD_CCkhRzmAanker219x25PM7YSu12_li4QtOGl363syqCpKX7vlXvIub7b_V1BU2qypVHfspL7qfSIja0edd7hSh' sandboxes: - id: 3874 name: Admin Sandbox username: f796d276ca4d13 password: 293caeb0f100e4 max_size: 0 status: active email_username: bcf11679c1-ad3171 email_username_enabled: false sent_messages_count: 316 forwarded_messages_count: 0 used: false forward_from_email_address: a3343-i3874@forward.mailtrap.info project_id: 2436 domain: localhost pop3_domain: localhost email_domain: localhost emails_count: 0 emails_unread_count: 0 last_message_sent_at: null smtp_ports: - 25 - 465 - 587 - 2525 pop3_ports: - 1100 - 9950 max_message_size: 5242880 permissions: can_read: true can_update: true can_destroy: true can_leave: false permissions: can_read: true can_update: true can_destroy: true can_leave: true Project: summary: Project with sandbox value: id: 2436 name: Admin Project share_links: admin: 'https://localhost/projects/2436/share/QEVuQwEAYWN-NIhmrB8qX6ZWzToqdOE9dw1ylIfOQ-_fKwYAD_CCkhRzmAanker219x25PM75TBaHgx1I4dsv058hghY_Ewaa3Vt7ET1aeg3ufVcit919V4baPLzxV9JaRzXWSjK' viewer: 'https://localhost/projects/2436/share/QEVuQwEAYWN-NIhmrB8qX6ZWzToqdOE9dw1ylIfOQ-_fKwYAD_CCkhRzmAanker219x25PM7YSu12_li4QtOGl363syqCpKX7vlXvIub7b_V1BU2qypVHfspL7qfSIja0edd7hSh' sandboxes: - id: 3874 name: Admin Sandbox username: f796d276ca4d13 password: 293caeb0f100e4 max_size: 0 status: active email_username: bcf11679c1-ad3171 email_username_enabled: false sent_messages_count: 316 forwarded_messages_count: 0 used: false forward_from_email_address: a3343-i3874@forward.mailtrap.info project_id: 2436 domain: localhost pop3_domain: localhost email_domain: localhost emails_count: 0 emails_unread_count: 0 last_message_sent_at: null smtp_ports: - 25 - 465 - 587 - 2525 pop3_ports: - 1100 - 9950 max_message_size: 5242880 permissions: can_read: true can_update: true can_destroy: true can_leave: false permissions: can_read: true can_update: true can_destroy: true can_leave: true Sandboxes: summary: List of sandboxes value: - id: 3538 name: Admin Sandbox username: b3a87978452ae1 password: 6be9fcfc613a7c max_size: 0 status: active email_username: b7eae548c3-54c542 email_username_enabled: false sent_messages_count: 52 forwarded_messages_count: 0 used: false forward_from_email_address: a3538-i4088@forward.mailtrap.info project_id: 2293 domain: localhost pop3_domain: localhost email_domain: localhost emails_count: 0 emails_unread_count: 0 last_message_sent_at: null smtp_ports: - 25 - 465 - 587 - 2525 pop3_ports: - 1100 - 9950 max_message_size: 5242880 permissions: can_read: true can_update: true can_destroy: true can_leave: true - id: 4089 name: Viewer Sandbox username: 1d0aa0282f7712 password: 5667a20f611ae7 max_size: 0 status: active email_username: f25402f8df-b77899 email_username_enabled: false sent_messages_count: 527 forwarded_messages_count: 0 used: false forward_from_email_address: a3538-i4089@forward.mailtrap.info project_id: 2293 domain: localhost pop3_domain: localhost email_domain: localhost emails_count: 0 emails_unread_count: 0 last_message_sent_at: null smtp_ports: - 25 - 465 - 587 - 2525 pop3_ports: - 1100 - 9950 max_message_size: 5242880 permissions: can_read: true can_update: false can_destroy: false can_leave: true 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' example: error: Incorrect API token PERMISSION_DENIED: description: Returns forbidden error message. Check your permissions. content: application/json: schema: $ref: '#/components/schemas/PermissionsDeniedResponse' example: errors: Account access forbidden NOT_FOUND: description: Returns not found error message content: application/json: schema: $ref: '#/components/schemas/NotFoundResponse' example: error: Not Found ProjectsResponse: description: |- Lists project attributes and inboxes of this project with their attributes. - **permissions** returns the permissions of the token for the project content: application/json: schema: type: array items: $ref: '#/components/schemas/Project' examples: ProjectsList: $ref: '#/components/examples/Projects' ProjectResponse: description: Returns project details content: application/json: schema: $ref: '#/components/schemas/Project' UpdateProjectResponse: description: Returns updated project details content: application/json: schema: $ref: '#/components/schemas/Project' examples: Project: $ref: '#/components/examples/Project' SandboxesResponse: description: |- Returns the list of sandboxes in the account to which the API token has access. - **permissions** returns the permissions of the token for the sandbox. content: application/json: schema: type: array items: $ref: '#/components/schemas/TestingSandbox' examples: SandboxesList: $ref: '#/components/examples/Sandboxes' SandboxResponse: description: |- Returns attributes of the sandbox. - **permissions** returns the permissions of the token for the sandbox. content: application/json: schema: $ref: '#/components/schemas/TestingSandbox' parameters: sandbox_id: description: Unique sandbox ID name: sandbox_id in: path required: true schema: type: integer format: int64 minimum: 1 example: 4015 message_id: description: Unique message ID name: message_id in: path required: true schema: type: integer format: int64 minimum: 1 example: 427 attachment_id: name: attachment_id description: Unique attachment ID in: path required: true schema: type: integer format: int64 minimum: 1 example: 1591 project_id: name: project_id description: Unique project ID in: path required: true schema: type: integer format: int64 minimum: 1 example: 4032