> For the complete documentation index, see [llms.txt](https://docs.maildrop.cc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.maildrop.cc/api-reference/delete-a-message.md).

# Delete a Message

### Do I need to delete messages from Maildrop?

In most cases, you shouldn't need to delete any messages. Mailboxes are temporary, and if no email messages are sent to a mailbox within 24 hours, the mailbox is completely erased automatically. Additionally, when there are a large amount of incoming messages, mailboxes that haven't seen messages recently may get emptied before the 24 hour window.

If you are sending a large number of automated messages (for example, testing sending out batches of messages to a large database of mock email addresses) then as a courtesy, you should delete those messages as part of your testing script cleanup phase.

## Deletes an individual message, by id, from a mailbox.

<mark style="color:green;">`POST`</mark> `https://api.maildrop.cc/graphql`

This GraphQL mutation takes a mailbox name and a message id as required parameters. This only returns a boolean of whether the message was deleted or not. Incorrect mailbox/id combinations will still return true.

#### Headers

| Name         | Type   | Description      |
| ------------ | ------ | ---------------- |
| Content-Type | String | application/json |

#### Request Body

| Name | Type   | Description                                                                       |
| ---- | ------ | --------------------------------------------------------------------------------- |
|      | String | '{"query":"mutation Example { delete(mailbox:\\"testing\\", id:\\"abc123\\") }"}' |

{% tabs %}
{% tab title="200: OK " %}

```json
{
    "data": {
        "delete": true
    }
}
```

{% endtab %}
{% endtabs %}

#### Examples

{% tabs %}
{% tab title="curl" %}

```bash
curl --request POST \
    --header 'content-type: application/json' \
    --url https://api.maildrop.cc/graphql \
    --data '{"query":"mutation Example { delete(mailbox:\"testing\", id:\"abc123\") }"}'
```

returns:

```json
{"data":{"delete":true}}
```

{% endtab %}

{% tab title="React" %}

```tsx
export const DELETE_MESSAGE = gql`
    mutation DeleteMessage($mailbox: String!, $id: String!) {
        delete(mailbox: $mailbox, id: $id)
    }
}`;

interface MutationReturn {
    delete: boolean;
}

interface MutationVariables {
    mailbox: string;
    id: string;
}

interface MyComponentProps {
    mailbox: string;
    id: string;
}

const MyComponent = (props: MyComponentProps) => {
    const [deleteMessage, { data, loading, error }] = useMutation<MutationReturn, MutationVariables>(DELETE_MESSAGE, {
        variables: { mailbox: props.mailbox, id: props.id }
    });
    return (
        <div>
            {loading && <div>Deleting...</div>}
            {!loading && <button onClick={deleteMessage}>Delete Message</button>}
            {!loading && error && <div>There was an error.</div>}
            {!loading && data?.delete && <div>Message deleted.</div>}            
        </div>
    );
};
```

{% endtab %}
{% endtabs %}
