---
agentTools:
  projectIndex: https://mailivery.readme.io/llms.txt
---

# Connect a Microsoft Mailbox

Onboard a Microsoft 365 / Outlook mailbox entirely through the Microsoft Graph API. Previously, inbox (IMAP) and sending (SMTP) access were each authorized separately through OAuth permissions rather than stored credentials. This flow unifies both into a single Microsoft Graph authorization, so there is no separate IMAP or SMTP step.

The request should be sent as an HTTP POST to https://app.mailivery.io/api/v1/campaigns/ms-graph. Upon successful validation, the API returns a Microsoft OAuth consent URL. The campaign is created only after the mailbox owner authorizes access and Microsoft redirects back to Mailivery's callback.

### Onboarding flow

1. POST this endpoint → receive `data.url`.
2. Send the mailbox owner to `data.url` → Microsoft consent screen.
3. The user authorizes → Microsoft redirects to Mailivery's callback → the campaign is created.

The resulting campaign has `imap_type = "ms-graph"` and `smtp_type = "outlook"` (free Microsoft domain) or `"office 365"` (corporate domain). Note that `smtp_type` is intentionally **not** `ms-graph`.

### After the user completes OAuth — what your system must do

Once the mailbox owner finishes Microsoft consent, Mailivery creates the campaign in `pending` status and sends a webhook to your configured webhook URL. A `pending` campaign is not warming up yet — warm-up starts only after you confirm the connection on your side.

Your webhook handler should:

1. Confirm that this mailbox was actually expected. Compare the email in the webhook payload against your own records to make sure a real user in your system intended to connect this mailbox. This prevents accidental or unauthorized campaigns from going live.
2. If expected → start warm-up. Call the `Start Warm-Up` (for new campaigns) or `Resume Warm-Up` (for previously paused campaigns) endpoint to move the campaign from `pending` into active warm-up.
3. If not expected → ignore or delete. Either call the delete-campaign endpoint, or simply leave the campaign in `pending` — it will not send or consume resources while pending.

# OpenAPI definition

```json
{
  "openapi": "3.0.3",
  "info": {
    "title": "Mailivery API",
    "description": "Welcome to the Mailivery API – the programmatic way to connect mailboxes, automate warm-up, and monitor deliverability from inside your own product or scripts.\n\n> **Terminology note — mailbox vs. campaign.** In the Mailivery dashboard, a connected sending account is called a **mailbox**. In the API, the same entity is modeled as a **campaign** — that's why request paths use `/campaigns/...`, identifiers are named `campaignId` / `campaign_id`, and the response schema is `Campaign`. Throughout this reference, when an endpoint description says \"mailbox,\" it refers to the same underlying record as `campaignId` in the URL or payload. No data difference — just two names for one thing.\n\n## Getting Started\n\nTo start integrating Mailivery into your application, follow these steps:\n\n### 1\\. **Sign Up for API Access**\n\nConnect with Our Product team and get Your API Keys.\n\n### 2\\. **API Documentation**\n\nRefer to our comprehensive API documentation for detailed information on endpoints, request and response formats, and authentication mechanisms. The documentation provides clear guidance on implementing Mailivery's API in your application.\n\n### 3\\. **Explore Code Samples**\n\nAccelerate your integration process by exploring our collection of code samples. These samples cover common use cases and showcase best practices for integrating Mailivery's API seamlessly.\n\n### 4\\. **Support and Resources**\n\nIf you encounter any challenges or have questions during the integration process, our dedicated support team is here to assist you.\n\n## Conclusion\n\nUnlock the full potential of Mailivery's email warm-up tool with our API. By seamlessly integrating our solution into your applications, you improve email deliverability and establish a robust sender reputation that stands the test of SPAM algorithms. Get started today and elevate your email marketing success with Mailivery.",
    "version": "1.1.0",
    "contact": {
      "name": "Suraj Jadhav",
      "email": "suraj@sourceitmarketing.com",
      "url": "https://mailivery.io"
    },
    "termsOfService": "https://mailivery.io",
    "license": {
      "name": "Custom License",
      "url": "https://mailivery.io"
    }
  },
  "servers": [
    {
      "url": "https://app.mailivery.io/api/v1",
      "description": "Production / Live server"
    },
    {
      "url": "https://app-staging.mailivery.io/api/v1",
      "description": "Staging / Testing server"
    }
  ],
  "paths": {
    "/campaigns/ms-graph": {
      "post": {
        "tags": [
          "Connecting Mailboxes"
        ],
        "summary": "Connect a Microsoft Mailbox",
        "description": "Onboard a Microsoft 365 / Outlook mailbox entirely through the Microsoft Graph API. Previously, inbox (IMAP) and sending (SMTP) access were each authorized separately through OAuth permissions rather than stored credentials. This flow unifies both into a single Microsoft Graph authorization, so there is no separate IMAP or SMTP step.\n\nThe request should be sent as an HTTP POST to https://app.mailivery.io/api/v1/campaigns/ms-graph. Upon successful validation, the API returns a Microsoft OAuth consent URL. The campaign is created only after the mailbox owner authorizes access and Microsoft redirects back to Mailivery's callback.\n\n### Onboarding flow\n\n1. POST this endpoint → receive `data.url`.\n2. Send the mailbox owner to `data.url` → Microsoft consent screen.\n3. The user authorizes → Microsoft redirects to Mailivery's callback → the campaign is created.\n\nThe resulting campaign has `imap_type = \"ms-graph\"` and `smtp_type = \"outlook\"` (free Microsoft domain) or `\"office 365\"` (corporate domain). Note that `smtp_type` is intentionally **not** `ms-graph`.\n\n### After the user completes OAuth — what your system must do\n\nOnce the mailbox owner finishes Microsoft consent, Mailivery creates the campaign in `pending` status and sends a webhook to your configured webhook URL. A `pending` campaign is not warming up yet — warm-up starts only after you confirm the connection on your side.\n\nYour webhook handler should:\n\n1. Confirm that this mailbox was actually expected. Compare the email in the webhook payload against your own records to make sure a real user in your system intended to connect this mailbox. This prevents accidental or unauthorized campaigns from going live.\n2. If expected → start warm-up. Call the `Start Warm-Up` (for new campaigns) or `Resume Warm-Up` (for previously paused campaigns) endpoint to move the campaign from `pending` into active warm-up.\n3. If not expected → ignore or delete. Either call the delete-campaign endpoint, or simply leave the campaign in `pending` — it will not send or consume resources while pending.",
        "operationId": "createCampaignWithMicrosoftGraph",
        "parameters": [
          {
            "$ref": "#/components/parameters/X-Request-ID"
          },
          {
            "$ref": "#/components/parameters/Accept"
          },
          {
            "$ref": "#/components/parameters/Content-Type"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "first_name": {
                    "type": "string",
                    "example": "Jane",
                    "maxLength": 255,
                    "description": "Mailbox owner first name."
                  },
                  "last_name": {
                    "type": "string",
                    "example": "Doe",
                    "maxLength": 255,
                    "nullable": true,
                    "description": "Mailbox owner last name."
                  },
                  "email": {
                    "type": "string",
                    "format": "email",
                    "example": "jane@contoso.com",
                    "maxLength": 255,
                    "description": "Microsoft 365 / Outlook email address. Must be unique across active campaigns."
                  },
                  "email_per_day": {
                    "type": "integer",
                    "example": 40,
                    "minimum": 0,
                    "maximum": 2000,
                    "nullable": true,
                    "description": "Daily send target for warmup, 0–2000. Required for the `user` role."
                  },
                  "response_rate": {
                    "type": "integer",
                    "example": 30,
                    "minimum": 0,
                    "maximum": 100,
                    "nullable": true,
                    "description": "Target reply rate percentage, 0–100. Required for the `user` role."
                  },
                  "meta": {
                    "type": "object",
                    "description": "Metadata object. Pass `{}` if unused.",
                    "properties": {
                      "tags": {
                        "type": "string",
                        "example": "warmup,q2",
                        "maxLength": 255,
                        "nullable": true,
                        "description": "Comma-separated tags to categorize the campaign."
                      }
                    }
                  },
                  "warmup_audience_type": {
                    "type": "string",
                    "enum": [
                      "inherit",
                      "all",
                      "business",
                      "consumer"
                    ],
                    "default": "inherit",
                    "example": "business",
                    "writeOnly": true,
                    "description": "Optional. Warm-up audience for the mailbox being created.\n\n- `all`      -> warm up with both business and consumer mailboxes.\n- `business` -> warm up with business mailboxes only.\n- `consumer` -> warm up with consumer mailboxes only.\n- `inherit`  -> follow the team-level setting. This is the default when the field is omitted."
                  }
                },
                "required": [
                  "first_name",
                  "email",
                  "meta"
                ]
              },
              "examples": {
                "Request": {
                  "value": {
                    "first_name": "Jane",
                    "last_name": "Doe",
                    "email": "jane@contoso.com",
                    "meta": {
                      "tags": "warmup,q2"
                    },
                    "email_per_day": 40,
                    "response_rate": 30
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Microsoft OAuth consent URL returned. The URL must be visited by the mailbox owner to complete authentication. Once they grant consent, Microsoft redirects to Mailivery's callback and the campaign is created automatically.\n",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "x-examples": {
                    "Example 1": {
                      "data": {
                        "url": "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=...&response_type=code&redirect_uri=...&scope=https://graph.microsoft.com/Mail.ReadWrite%20https://graph.microsoft.com/Mail.Send&state=..."
                      },
                      "success": true,
                      "status": 200,
                      "code": "MS_GRAPH_EMBED_FORM_URL_FETCHED",
                      "message": "Microsoft Graph embed form url fetched successfully"
                    }
                  },
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "url": {
                          "type": "string",
                          "format": "uri",
                          "description": "Microsoft OAuth consent URL. Redirect the mailbox owner here to finish onboarding. The campaign is created on the callback after authorization.",
                          "example": "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=...&response_type=code&redirect_uri=...&scope=https://graph.microsoft.com/Mail.ReadWrite%20https://graph.microsoft.com/Mail.Send&state=..."
                        }
                      }
                    },
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "status": {
                      "type": "integer",
                      "example": 200
                    },
                    "code": {
                      "type": "string",
                      "example": "MS_GRAPH_EMBED_FORM_URL_FETCHED"
                    },
                    "message": {
                      "type": "string",
                      "example": "Microsoft Graph embed form url fetched successfully"
                    }
                  }
                },
                "examples": {
                  "Success": {
                    "value": {
                      "data": {
                        "url": "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=...&response_type=code&redirect_uri=...&scope=https://graph.microsoft.com/Mail.ReadWrite%20https://graph.microsoft.com/Mail.Send&state=..."
                      },
                      "success": true,
                      "status": 200,
                      "code": "MS_GRAPH_EMBED_FORM_URL_FETCHED",
                      "message": "Microsoft Graph embed form url fetched successfully"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "example": []
                    },
                    "success": {
                      "type": "boolean",
                      "example": false
                    },
                    "status": {
                      "type": "number",
                      "example": 400
                    },
                    "code": {
                      "type": "string",
                      "example": "VALIDATION_ERROR"
                    },
                    "message": {
                      "type": "string",
                      "example": "Please check the request parameters"
                    },
                    "error": {
                      "type": "object",
                      "properties": {
                        "email": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          },
                          "example": [
                            "The email has already been taken."
                          ]
                        }
                      }
                    }
                  }
                },
                "examples": {
                  "Validation Error": {
                    "value": {
                      "data": [],
                      "success": false,
                      "status": 400,
                      "code": "VALIDATION_ERROR",
                      "message": "Please check the request parameters",
                      "error": {
                        "email": [
                          "The email has already been taken."
                        ]
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "example": []
                    },
                    "success": {
                      "type": "boolean",
                      "example": false
                    },
                    "status": {
                      "type": "number",
                      "example": 401
                    },
                    "code": {
                      "type": "string",
                      "example": "UNAUTHORIZED"
                    },
                    "message": {
                      "type": "string",
                      "example": "Unauthenticated"
                    }
                  }
                },
                "examples": {
                  "Unauthorized": {
                    "value": {
                      "data": [],
                      "success": false,
                      "status": 401,
                      "code": "UNAUTHORIZED",
                      "message": "Unauthenticated"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Authorization Error. Returned with code `AUTHORIZATION_ERROR` when the caller is not allowed to create a campaign.\n",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "example": []
                    },
                    "success": {
                      "type": "boolean",
                      "example": false
                    },
                    "status": {
                      "type": "number",
                      "example": 403
                    },
                    "code": {
                      "type": "string",
                      "example": "AUTHORIZATION_ERROR"
                    },
                    "message": {
                      "type": "string",
                      "example": "You are not allowed to create campaign."
                    }
                  }
                },
                "examples": {
                  "Authorization Error": {
                    "value": {
                      "data": [],
                      "success": false,
                      "status": 403,
                      "code": "AUTHORIZATION_ERROR",
                      "message": "You are not allowed to create campaign."
                    }
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "parameters": {
      "X-Request-ID": {
        "name": "X-Request-ID",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string",
          "example": "43873599-9e19-42e6-9a5b-b2bc0a264a28"
        },
        "description": "Any unique string, timestamp, or UUID for logging."
      },
      "Content-Type": {
        "name": "Content-Type",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string",
          "default": "multipart/form-data",
          "example": "application/x-www-form-urlencoded"
        },
        "description": "Request Content-Type"
      },
      "Accept": {
        "name": "Accept",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string",
          "default": "application/json",
          "example": "application/json"
        },
        "description": "Expected Type for response"
      }
    }
  },
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Connecting Mailboxes",
      "description": "Endpoints for connecting new mailboxes via SMTP, Gmail, SendGrid, and the secure embed form."
    }
  ],
  "x-tagGroups": [
    {
      "name": "Getting Started",
      "tags": [
        "Mailivery API Introduction"
      ]
    },
    {
      "name": "Connecting Mailboxes",
      "tags": [
        "Connecting Mailboxes"
      ]
    },
    {
      "name": "Bulk Import",
      "tags": [
        "Bulk Import"
      ]
    },
    {
      "name": "Warm-Up Controls",
      "tags": [
        "Warm-Up Controls"
      ]
    },
    {
      "name": "Managing Mailboxes",
      "tags": [
        "Managing Mailboxes"
      ]
    },
    {
      "name": "Metrics & Health",
      "tags": [
        "Metrics & Health"
      ]
    },
    {
      "name": "Custom Warm-Up Templates",
      "tags": [
        "Custom Warm-Up Templates"
      ]
    },
    {
      "name": "Yahoo Deliverability Filter",
      "tags": [
        "Yahoo Deliverability Filter"
      ]
    },
    {
      "name": "Warm-Up Audience",
      "tags": [
        "Warm-Up Audience"
      ]
    },
    {
      "name": "Object Structures",
      "tags": [
        "Object Structures"
      ]
    },
    {
      "name": "Webhooks",
      "tags": [
        "Webhooks"
      ]
    },
    {
      "name": "Connection Recheck",
      "tags": [
        "Connection Health"
      ]
    },
    {
      "name": "Inbox Placement Test (Beta)",
      "tags": [
        "IPT - Tests",
        "IPT - Results",
        "IPT - Schedule",
        "IPT - Resources"
      ]
    },
    {
      "name": "Blacklist Monitoring",
      "tags": [
        "Blacklist Monitoring"
      ]
    },
    {
      "name": "Email Verification",
      "tags": [
        "Email Verification"
      ]
    }
  ],
  "x-readme": {
    "explorer-enabled": true,
    "proxy-enabled": true
  },
  "_id": {
    "buffer": {
      "0": 106,
      "1": 206,
      "2": 145,
      "3": 36,
      "4": 58,
      "5": 253,
      "6": 8,
      "7": 42,
      "8": 44,
      "9": 142,
      "10": 191,
      "11": 142
    }
  }
}
```