Auto-log inbox emails to HubSpot contacts every 15 minutes
Every 15 minutes, sync sent and received email from your mailbox to matching HubSpot contacts, so every conversation lands on the right record.
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.
Additional information
What does this prompt do?
- Runs every 15 minutes and picks up every new sent or received email from your inbox.
- Matches each email to a HubSpot contact by email address and quietly skips anyone who is not already in your CRM.
- Files a tidy note on the matching contact, plus their company and any open deal, with the direction, subject, timestamp, and a snippet of the body.
- Keeps a checkpoint of what it has already logged so re-runs never double up on the same email.
What do I need to use this?
- A HubSpot login with permission to search contacts and create notes.
- An Aurinko account connected to your Gmail, Outlook, Exchange, iCloud, or IMAP mailbox.
- A team that mostly emails people already in HubSpot (unknown addresses are skipped).
How can I customize it?
- Change how often it runs, from every 15 minutes to hourly or once a day.
- Adjust the note body length, or add fields like the rep's name or the mailbox folder.
- Restrict it to a specific label or folder so only real sales conversations get logged.
Frequently asked questions
Will this log emails from people who are not in HubSpot yet?
Does this work with Gmail and Outlook?
How does it avoid logging the same email twice?
Will the notes show up on companies and deals too?
Do I need HubSpot Sales Hub for this?
Related templates
Never chase your reps for email logs again.
Connect Aurinko and HubSpot once, and every sent or received email lands on the right contact every 15 minutes.