Auto-log inbox emails to HubSpot contacts every 15 minutes

By General Input

Every 15 minutes, sync sent and received email from your mailbox to matching HubSpot contacts, so every conversation lands on the right record.

Integrations

  • Aurinko
  • HubSpot

Type

Deterministic Code

Categories

  • Sales
  • Operations

Build me a code workflow that keeps HubSpot in sync with the email conversations my team is actually having. It should run on a cron trigger every 15 minutes and needs no LLM, no drafting, and no Slack. This is a pure sync.

On each run:

1. Call Aurinko's List Email Messages operation against my mailbox, filtered to messages received or sent since the last successful run. Persist a checkpoint between runs (the max processed message timestamp, plus the set of message ids from the most recent window) so we do not reprocess messages we have already handled. Page through nextPageToken until exhausted.

2. For each message, work out the counterparty email address. On inbound messages, use the From address (the non-me party). On outbound messages, use the first To address. Skip messages where you cannot determine a counterparty, and skip anything where the counterparty is my own mailbox (self-sent notes).

3. Look the counterparty address up in HubSpot with Search Contacts, filtering on the email property (equality match). If no contact matches, skip the message quietly. Cache lookups within a run so repeated addresses do not burn extra search calls (HubSpot's search API is 4 requests/second).

4. If a contact matches, call HubSpot Create Note. Associate the note with the contact. If the search response surfaced an associated company or an open deal for that contact, associate the note with those records too, using the inline associations array.

5. The note body (hs_note_body) should be a short, structured plain-text block with these fields, one per line: Direction (Inbound / Outbound), Subject, Timestamp (ISO 8601), From, To, then a blank line and the first ~500 characters of the plain-text body of the email. If the body is longer than 500 chars, truncate and append a trailing ellipsis. Set hs_timestamp on the note to the email's timestamp so it slots into the HubSpot timeline in the right place.

6. Deduplicate by keeping the id of every message already logged in the checkpoint state. On re-runs, skip anything already logged even if it falls inside the polling window.

Error handling: if HubSpot returns 429, respect the Retry-After header and back off. If Aurinko returns 429 or an upstream provider throttle, stop the current run cleanly and let the next 15-minute tick pick up where we left off. Do not advance the checkpoint past any message that failed to log, so the next run retries it.

Do not create HubSpot contacts, do not send anything, do not use an LLM. Just deterministic email-to-note sync.

Related prompts

Explore more prompts
Turn Mailjet email clicks into ranked HubSpot follow-upsiMessage campaign console with pre-flight checks and delivery boardA searchable RFP answer library your bid team drafts fromSee which target accounts just started advertising on LinkedInAccount health board that puts product usage next to your CRMLook up a customer's full chat history mid conversationLusha prospecting workbench with credit-safe revealsWhich companies your LinkedIn ads reach, matched to your CRMLead response desk with a running clock on every new leadApprove Lusha enrichment field by field before HubSpot saves it