# 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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.maildrop.cc/api-reference/delete-a-message.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
