# Reply to received emails

> Reply in-thread by setting In-Reply-To (and References) to the received message_id when sending via POST /emails.

Email clients **thread** messages using the `Message-ID` header. To reply to a received email so it lands in the same conversation, send a new email via [POST /emails](https://www.sendping.co/docs/api/emails-send) with an `In-Reply-To` header set to the original message's `message_id`. Start the subject with `Re:` so clients group the replies together.

## The quick way: the reply endpoint

You usually don't need to manage threading headers yourself. [`POST /emails/receiving/:id/reply`](https://www.sendping.co/docs/api/receiving-reply) does all of it in one call: it derives the recipient from the received email's `Reply-To` (falling back to `From`), sets `In-Reply-To`/`References` to the received `message_id`, and defaults the subject to `Re: …`. Pass a verified `from` and the reply `html`/`text`.

**Node.js**

```js
import { SendPing } from 'sendping';

const mb = new SendPing('mb_xxxxxxxxx');

const { data, error } = await mb.emails.receiving.reply('56761188-7520-42d8-8898-ff6fc54ce618', {
  "from": "Acme <hello@yourdomain.com>",
  "html": "<p>Thanks for your email!</p>"
});
console.log({ data, error });
```

**Ruby**

```ruby
require "sendping"

SendPing.api_key = "mb_xxxxxxxxx"

SendPing::Emails::Receiving.reply("56761188-7520-42d8-8898-ff6fc54ce618", {
  "from": "Acme <hello@yourdomain.com>",
  "html": "<p>Thanks for your email!</p>"
})
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

use SendPing\SendPing;

$sendping = SendPing::client('mb_xxxxxxxxx');

$sendping->emails->receiving->reply('56761188-7520-42d8-8898-ff6fc54ce618', [
  'from' => "Acme <hello@yourdomain.com>",
  'html' => "<p>Thanks for your email!</p>"
]);
```

**Python**

```python
import sendping

sendping.api_key = "mb_xxxxxxxxx"

sendping.Emails.Receiving.reply("56761188-7520-42d8-8898-ff6fc54ce618", {
  "from": "Acme <hello@yourdomain.com>",
  "html": "<p>Thanks for your email!</p>"
})
```

**Go**

```go
import "github.com/shekhu10/sendping-sdks/sendping-go"

client := sendping.NewClient("mb_xxxxxxxxx")

replied, err := client.Emails.Receiving.Reply("56761188-7520-42d8-8898-ff6fc54ce618", &sendping.ReplyReceivedEmailRequest{
    From: "Acme <hello@yourdomain.com>",
    Html: "<p>Thanks for your email!</p>",
})
```

**Rust**

```rust
use sendping::{ReplyReceivedEmailOptions, SendPing};

let mb = SendPing::new("mb_xxxxxxxxx");

let params = ReplyReceivedEmailOptions::new("Acme <hello@yourdomain.com>")
    .with_html("<p>Thanks for your email!</p>");
let _replied = mb.emails.receiving.reply("56761188-7520-42d8-8898-ff6fc54ce618", params).await?;
```

**Java**

```java
import co.sendping.SendPing;
import co.sendping.SendPingResponse;
import co.sendping.requests.ReplyEmailRequest;

SendPing sendping = new SendPing("mb_xxxxxxxxx");

ReplyEmailRequest request = ReplyEmailRequest.builder()
        .from("Acme <hello@yourdomain.com>")
        .html("<p>Thanks for your email!</p>")
        .build();

SendPingResponse response = sendping.emails().receiving().reply(
        "56761188-7520-42d8-8898-ff6fc54ce618",
        request);
```

**.NET**

```csharp
using SendPing;

ISendPing sendping = SendPingClient.Create("mb_xxxxxxxxx");

var resp = await sendping.ReceivedEmailReplyAsync("56761188-7520-42d8-8898-ff6fc54ce618", new ReceivedEmailReplyOptions
{
    From = "Acme <hello@yourdomain.com>",
    HtmlBody = "<p>Thanks for your email!</p>",
});
```

**cURL**

```bash
curl -X POST 'https://www.sendping.co/api/emails/receiving/56761188-7520-42d8-8898-ff6fc54ce618/reply' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "from": "Acme <hello@yourdomain.com>",
  "html": "<p>Thanks for your email!</p>"
}'
```

**CLI**

```bash
sendping emails receiving reply 56761188-7520-42d8-8898-ff6fc54ce618 \
  --from 'Acme <hello@yourdomain.com>' \
  --html '<p>Thanks for your email!</p>'
```

The rest of this guide covers the **manual** approach — replying via [POST /emails](https://www.sendping.co/docs/api/emails-send) with explicit threading headers — for when you need full control over the recipient, headers, or thread structure.

## Get the message ID

The `message_id` is included in the [email.received](https://www.sendping.co/docs/receiving/introduction) webhook payload:

```json
{
  "type": "email.received",
  "data": {
    "email_id": "56761188-7520-42d8-8898-ff6fc54ce618",
    "message_id": "<111-222-333@email.example.com>",
    "subject": "Sending this example",
    "from": "Acme <onboarding@test.sendping.co>",
    "to": ["delivered@test.sendping.co"]
  }
}
```

Use `event.data.message_id` as the `In-Reply-To` header value when sending your reply.

## Send a reply in thread

Set the `In-Reply-To` header to the received `message_id` and prefix the subject with `Re:`. See [Custom headers](https://www.sendping.co/docs/emails/headers) for how SendPing writes custom MIME headers.

**Node.js**

```js
import { SendPing } from 'sendping';

const mb = new SendPing('mb_xxxxxxxxx');

const { data, error } = await mb.emails.send({
  "from": "Acme <hello@yourdomain.com>",
  "to": ["delivered@test.sendping.co"],
  "subject": "Re: Sending this example",
  "html": "<p>Thanks for your email!</p>",
  "headers": {
    "In-Reply-To": "<111-222-333@email.example.com>"
  }
});
console.log({ data, error });
```

**Ruby**

```ruby
require "sendping"

SendPing.api_key = "mb_xxxxxxxxx"

SendPing::Emails.send({
  "from": "Acme <hello@yourdomain.com>",
  "to": [
    "delivered@test.sendping.co"
  ],
  "subject": "Re: Sending this example",
  "html": "<p>Thanks for your email!</p>",
  "headers": {
    "In-Reply-To": "<111-222-333@email.example.com>"
  }
})
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

use SendPing\SendPing;

$sendping = SendPing::client('mb_xxxxxxxxx');

$sendping->emails->send([
  'from' => "Acme <hello@yourdomain.com>",
  'to' => [
    "delivered@test.sendping.co"
  ],
  'subject' => "Re: Sending this example",
  'html' => "<p>Thanks for your email!</p>",
  'headers' => [
    'In-Reply-To' => "<111-222-333@email.example.com>"
  ]
]);
```

**Python**

```python
import sendping

sendping.api_key = "mb_xxxxxxxxx"

sendping.Emails.send({
  "from": "Acme <hello@yourdomain.com>",
  "to": [
    "delivered@test.sendping.co"
  ],
  "subject": "Re: Sending this example",
  "html": "<p>Thanks for your email!</p>",
  "headers": {
    "In-Reply-To": "<111-222-333@email.example.com>"
  }
})
```

**Go**

```go
import "github.com/shekhu10/sendping-sdks/sendping-go"

client := sendping.NewClient("mb_xxxxxxxxx")

sent, err := client.Emails.Send(&sendping.SendEmailRequest{
    From:    "Acme <hello@yourdomain.com>",
    To:      []string{"delivered@test.sendping.co"},
    Subject: "Re: Sending this example",
    Html:    "<p>Thanks for your email!</p>",
    Headers: map[string]string{"In-Reply-To": "<111-222-333@email.example.com>"},
})
```

**Rust**

```rust
use sendping::{SendEmailOptions, SendPing};

let mb = SendPing::new("mb_xxxxxxxxx");

let params = SendEmailOptions::new(
    "Acme <hello@yourdomain.com>",
    ["delivered@test.sendping.co"],
    "Re: Sending this example",
)
.with_html("<p>Thanks for your email!</p>")
.with_header("In-Reply-To", "<111-222-333@email.example.com>");
let _sent = mb.emails.send(params).await?;
```

**Java**

```java
import co.sendping.SendPing;
import co.sendping.SendPingResponse;
import co.sendping.requests.SendEmailRequest;

SendPing sendping = new SendPing("mb_xxxxxxxxx");

SendEmailRequest request = SendEmailRequest.builder()
        .from("Acme <hello@yourdomain.com>")
        .to("delivered@test.sendping.co")
        .subject("Re: Sending this example")
        .html("<p>Thanks for your email!</p>")
        .header("In-Reply-To", "<111-222-333@email.example.com>")
        .build();

SendPingResponse response = sendping.emails().send(request);
```

**.NET**

```csharp
using SendPing;

ISendPing sendping = SendPingClient.Create("mb_xxxxxxxxx");

var resp = await sendping.EmailSendAsync(new EmailMessage
{
    From = "Acme <hello@yourdomain.com>",
    To = "delivered@test.sendping.co",
    Subject = "Re: Sending this example",
    HtmlBody = "<p>Thanks for your email!</p>",
    Headers = new Dictionary<string, string>
    {
        ["In-Reply-To"] = "<111-222-333@email.example.com>",
    },
});
```

**cURL**

```bash
curl -X POST 'https://www.sendping.co/api/emails' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "from": "Acme <hello@yourdomain.com>",
  "to": ["delivered@test.sendping.co"],
  "subject": "Re: Sending this example",
  "html": "<p>Thanks for your email!</p>",
  "headers": {
    "In-Reply-To": "<111-222-333@email.example.com>"
  }
}'
```

**CLI**

```bash
sendping emails send \
  --from 'Acme <hello@yourdomain.com>' \
  --to 'delivered@test.sendping.co' \
  --subject 'Re: Sending this example' \
  --html '<p>Thanks for your email!</p>' \
  --headers '{"In-Reply-To":"<111-222-333@email.example.com>"}'
```

## Reply headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `In-Reply-To` | string | Yes | The `message_id` of the message you are replying to (e.g. `<111-222-333@email.example.com>`). |
| `References` | string | No | Space-separated list of every prior `message_id` in the thread, ending with the one you are replying to. Used for deep threading across multiple replies. |

## Replying multiple times in a thread

When you reply more than once in the same conversation, also set the `References` header to all previous `message_id`s separated by spaces, ending with the current one. This helps clients keep the thread structure correct.

**Node.js**

```js
import { SendPing } from 'sendping';

const mb = new SendPing('mb_xxxxxxxxx');

const { data, error } = await mb.emails.send({
  "from": "Acme <hello@yourdomain.com>",
  "to": ["delivered@test.sendping.co"],
  "subject": "Re: Sending this example",
  "html": "<p>Thanks for your email!</p>",
  "headers": {
    "In-Reply-To": "<111-222-333@email.example.com>",
    "References": "<msg_id1@domain.com> <msg_id2@domain.com> <111-222-333@email.example.com>"
  }
});
console.log({ data, error });
```

**Ruby**

```ruby
require "sendping"

SendPing.api_key = "mb_xxxxxxxxx"

SendPing::Emails.send({
  "from": "Acme <hello@yourdomain.com>",
  "to": [
    "delivered@test.sendping.co"
  ],
  "subject": "Re: Sending this example",
  "html": "<p>Thanks for your email!</p>",
  "headers": {
    "In-Reply-To": "<111-222-333@email.example.com>",
    "References": "<msg_id1@domain.com> <msg_id2@domain.com> <111-222-333@email.example.com>"
  }
})
```

**PHP**

```php
<?php
require 'vendor/autoload.php';

use SendPing\SendPing;

$sendping = SendPing::client('mb_xxxxxxxxx');

$sendping->emails->send([
  'from' => "Acme <hello@yourdomain.com>",
  'to' => [
    "delivered@test.sendping.co"
  ],
  'subject' => "Re: Sending this example",
  'html' => "<p>Thanks for your email!</p>",
  'headers' => [
    'In-Reply-To' => "<111-222-333@email.example.com>",
    'References' => "<msg_id1@domain.com> <msg_id2@domain.com> <111-222-333@email.example.com>"
  ]
]);
```

**Python**

```python
import sendping

sendping.api_key = "mb_xxxxxxxxx"

sendping.Emails.send({
  "from": "Acme <hello@yourdomain.com>",
  "to": [
    "delivered@test.sendping.co"
  ],
  "subject": "Re: Sending this example",
  "html": "<p>Thanks for your email!</p>",
  "headers": {
    "In-Reply-To": "<111-222-333@email.example.com>",
    "References": "<msg_id1@domain.com> <msg_id2@domain.com> <111-222-333@email.example.com>"
  }
})
```

**Go**

```go
import "github.com/shekhu10/sendping-sdks/sendping-go"

client := sendping.NewClient("mb_xxxxxxxxx")

sent, err := client.Emails.Send(&sendping.SendEmailRequest{
    From:    "Acme <hello@yourdomain.com>",
    To:      []string{"delivered@test.sendping.co"},
    Subject: "Re: Sending this example",
    Html:    "<p>Thanks for your email!</p>",
    Headers: map[string]string{
        "In-Reply-To": "<111-222-333@email.example.com>",
        "References":  "<msg_id1@domain.com> <msg_id2@domain.com> <111-222-333@email.example.com>",
    },
})
```

**Rust**

```rust
use sendping::{SendEmailOptions, SendPing};

let mb = SendPing::new("mb_xxxxxxxxx");

let params = SendEmailOptions::new(
    "Acme <hello@yourdomain.com>",
    ["delivered@test.sendping.co"],
    "Re: Sending this example",
)
.with_html("<p>Thanks for your email!</p>")
.with_header("In-Reply-To", "<111-222-333@email.example.com>")
.with_header("References", "<msg_id1@domain.com> <msg_id2@domain.com> <111-222-333@email.example.com>");
let _sent = mb.emails.send(params).await?;
```

**Java**

```java
import co.sendping.SendPing;
import co.sendping.SendPingResponse;
import co.sendping.requests.SendEmailRequest;

SendPing sendping = new SendPing("mb_xxxxxxxxx");

SendEmailRequest request = SendEmailRequest.builder()
        .from("Acme <hello@yourdomain.com>")
        .to("delivered@test.sendping.co")
        .subject("Re: Sending this example")
        .html("<p>Thanks for your email!</p>")
        .header("In-Reply-To", "<111-222-333@email.example.com>")
        .header("References", "<msg_id1@domain.com> <msg_id2@domain.com> <111-222-333@email.example.com>")
        .build();

SendPingResponse response = sendping.emails().send(request);
```

**.NET**

```csharp
using SendPing;

ISendPing sendping = SendPingClient.Create("mb_xxxxxxxxx");

var resp = await sendping.EmailSendAsync(new EmailMessage
{
    From = "Acme <hello@yourdomain.com>",
    To = "delivered@test.sendping.co",
    Subject = "Re: Sending this example",
    HtmlBody = "<p>Thanks for your email!</p>",
    Headers = new Dictionary<string, string>
    {
        ["In-Reply-To"] = "<111-222-333@email.example.com>",
        ["References"] = "<msg_id1@domain.com> <msg_id2@domain.com> <111-222-333@email.example.com>",
    },
});
```

**cURL**

```bash
curl -X POST 'https://www.sendping.co/api/emails' \
  -H 'Authorization: Bearer mb_xxxxxxxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "from": "Acme <hello@yourdomain.com>",
  "to": ["delivered@test.sendping.co"],
  "subject": "Re: Sending this example",
  "html": "<p>Thanks for your email!</p>",
  "headers": {
    "In-Reply-To": "<111-222-333@email.example.com>",
    "References": "<msg_id1@domain.com> <msg_id2@domain.com> <111-222-333@email.example.com>"
  }
}'
```

**CLI**

```bash
sendping emails send \
  --from 'Acme <hello@yourdomain.com>' \
  --to 'delivered@test.sendping.co' \
  --subject 'Re: Sending this example' \
  --html '<p>Thanks for your email!</p>' \
  --headers '{"In-Reply-To":"<111-222-333@email.example.com>","References":"<msg_id1@domain.com> <msg_id2@domain.com> <111-222-333@email.example.com>"}'
```

> **Note:** The reply's `from` must be on a [verified sending domain](https://www.sendping.co/docs/domains/managing). The reply is an ordinary outbound send via `POST /emails`; the `In-Reply-To` / `References` headers are what place it in the existing thread.
