Answer unanswered emails stored in MySQL with Claude: one reply per thread, using thread history and SQL context, then mark them answered with your Post Query.
Answer the pending emails returned by the Pending Query, one reply per thread.
Variables
Database the Pending, History, Context, Post and Error Queries run against.
SQL (Jinja) returning the messages to answer. Required columns: id, thread_id, sender, subject, body, email_date. Optional: message_id, reply_to, email_references, recipients, attachment_names, auto_submitted, precedence, list_id. Rows are grouped by thread_id and each thread gets one reply. It must not return rows the Post Query has marked, or they are answered again.
Optional SQL (Jinja) returning earlier messages of the thread, run per thread. Variables: {{ thread_id }}, {{ history_limit }}. Columns: body and reply_body (one row = message + our answer), or body and direction (inbound/outbound); email_date to order them.
Maximum number of earlier history rows given to Claude. 0 disables history.
JSON values available as {{ name }} in every query and in the Unable to Process Reply.
Claude API key used to generate replies.
Claude model that writes the replies.
How much reasoning Claude spends per reply. Higher is more thorough but slower and more expensive; medium suits most support email.
How the assistant should answer: tone, scope, signature, policies. Used when the Context Query returns no instructions column (or it is empty).
Optional model settings. Only Max Tokens is used; current Claude models reject temperature/top p/top k, so they are not sent.
Optional SQL (Jinja) run per thread. A column named instructions (first non-empty value) replaces the Default Instructions; all other columns are given to Claude as reference context. Variables: {{ sender }}, {{ sender_address }}, {{ subject }}, {{ body }}, {{ thread_id }} and the User Defined Parameters. Message values are passed as safe bind parameters: use them as a whole value ('{{ sender_address }}'), not inside a longer string (use CONCAT('%', {{ subject }}, '%')).
SMTP server used to send the replies.
Address replies are sent from. Defaults to the SMTP username. Messages from this address are never answered.
Send the Unable to Process Reply when a thread cannot be answered. If disabled, only a warning is logged and the Post Query runs with status unable.
Reply sent when a thread cannot be answered. Jinja: {{ reason }}, {{ sender }}, {{ subject }} and User Defined Parameters.
Generate replies and log them without sending. The Post and Error Queries do not run.
SQL (Jinja) that marks a message as handled, run once per pending row after its thread was answered, refused or skipped. Variables (bind parameters): {{ id }}, {{ message_id }}, {{ thread_id }}, {{ status }} (replied | unable | skipped), {{ reason }}, {{ reply_message_id }}, {{ reply_body }}, {{ reply_to }}, {{ replied_at }}, {{ is_reply_target }} (1 for the message the reply answers).
Optional SQL (Jinja) run per row when a thread fails (AI or sending error). The rows stay pending and are retried next run. Variables: {{ id }}, {{ message_id }}, {{ thread_id }}, {{ error }}.