Guide
Reply to an Email from the Command Line
Sending a fresh email from a script is easy; replying so the message lands in the right thread is the part people get wrong. A reply isn't just a send to the original sender — it has to carry the headers that link it to the conversation, or it shows up as a stray new message. This shows how to find the message you're answering, reply in-thread with one flag, and add CC or reply-all without breaking the thread.
Written by Pouya Sanooei Software Engineer
Command references used in this guide: nylas email send, nylas email list, and nylas email search.
How do you reply to an email from the command line?
You reply by passing the original message's ID to nylas email send --reply-to. That single flag tells the API to attach the threading headers — In-Reply-To and References — that link your message to the existing conversation, so Gmail, Outlook, and other clients show it inside the thread rather than as a new email. Without it, your reply is technically just a new message to the same person.
Those headers come from the email standard, RFC 5322: In-Reply-To names the message you're answering, and References lists the chain back to the thread's root. Mail clients use them to group messages — the same headers behind the Gmail API thread model — which is why a reply that omits them breaks threading even when the subject still starts with “Re:”. The CLI sets them for you from the message ID.
How do you find the message ID to reply to?
Every message has an id in the CLI's JSON output, and that's what --reply-to wants. List recent mail or search for the specific message with --json, then pull the id with jq. The example finds the most recent message from a sender and captures its ID into a shell variable for the reply.
# Find the message you want to answer and grab its id
MSG_ID=$(nylas email search "from:alice@example.com" --json --limit 1 \
| jq -r '.[0].id')
echo "Replying to message: $MSG_ID"How do you reply in the same thread?
With the ID in hand, run nylas email send --reply-to "$MSG_ID" and add your body. The reply sends from your connected account, inherits the conversation's threading, and lands in the same thread in the recipient's client. You don't need to set the subject or the To address manually for a basic reply — the message ID carries the context.
# Reply in the original thread — one flag does the threading
nylas email send --reply-to "$MSG_ID" \
--body "Thanks Alice — confirming the numbers look right. Sending the deck shortly."The result is a properly threaded reply, the same as hitting Reply in a mail client, but scriptable. This is what turns an automation from “sends a new email that breaks the conversation” into “answers in place,” which matters for support tools and agents that respond to ongoing threads.
How do you reply-all or add CC?
A reply-all keeps everyone on the original message in the loop. Add the other recipients with --cc (or --bcc) alongside --reply-to, and the threading still holds — the message joins the conversation and copies the additional addresses. Pull the original's recipients from the JSON if you want to reconstruct the full participant list programmatically.
# Reply-all: keep the thread and copy the other participants
nylas email send --reply-to "$MSG_ID" \
--cc "bob@example.com,carol@example.com" \
--body "Looping in Bob and Carol — same confirmation applies."For replies an automation generates, consider composing a draft first so a person can review before it sends — the same human-in-the-loop pattern used for AI email agents. See work with email threads for reading a whole conversation and manage email drafts for the review-before-send flow.
Next steps
- Work with email threads — read a full conversation from the terminal
- Manage email drafts — compose and review before sending
- Send email from the terminal — the full send reference
- Extract email data with jq — pull IDs and addresses from JSON
- Draft email with smart compose — generate a reply from a prompt
- Full command reference — every flag and subcommand documented