Open tracking for the Gmail API and Microsoft Graph
Updated 2 December 2026
Short answer: neither the Gmail API nor Microsoft Graph tells you whether a sent
message was opened. To get opens for mail that a program or an AI agent sends through
them, add one tracking image to the HTML body before the send call. With didtheyopen that
is one extra call per email: POST /v1/messages returns a pixel URL, the tag
goes before </body>, and opens come back through a scheduled feed or a
signed webhook.
Open tracking for the email your agent already sends from your Gmail or Outlook. This page is for developers who write the send code. If you only talk to an agent, use the Gmail guide or the Outlook guide.
What the mail APIs give you
-
Gmail API.
users.messages.sendandusers.drafts.sendtake a raw MIME message and return the message and thread ids. There is no open event and no open-tracking option. -
Microsoft Graph.
sendMailtakes a JSON message with an HTML or text body. There is no open event. Graph can attach a receipt request, which asks the recipient for permission, and that is a different thing from open tracking. - Inbox trackers. Trackers such as Mailtrack work from an extension, an add-on or an app, where you press Send yourself. When code sends through the Gmail API, Graph or SMTP, none of those is in the path.
Add open tracking in five steps
-
Get an agent key.
POST https://p.didtheyopen.com/signupcreates an account with no email needed, and an agent can call it itself. Store the agent key asDIDTHEYOPEN_API_KEY. Never put it in a URL or a log. -
Create a tracked message for every email you send. Use your own
client_ref, and send the same value as theIdempotency-Key, so a retry returns the same pixel and never a duplicate. -
Insert the tag at the end of the HTML body, before
</body>. One pixel per email, in the HTML part only. -
Send as you already do. With the Gmail API, put the HTML in the
text/htmlpart of the MIME message, base64url-encode it, and callusers.messages.send. With Graph, set the message body tocontentType: "HTML"and callsendMail. -
Fetch opens. Poll
GET /v1/events?since=<next_since>&summary=1every 10 to 15 minutes, or register a webhook and receive notable opens as a signed POST.
Example
Create the tracked message:
curl -X POST https://p.didtheyopen.com/v1/messages \
-H "Authorization: Bearer $DIDTHEYOPEN_API_KEY" \
-H "Idempotency-Key: proposal-dana-1" \
-H "Content-Type: application/json" \
-d '{"client_ref":"proposal-dana-1","sender_label":"work","label":"Dana Levi"}'
The 201 response includes pixel_url, shown once. Insert exactly this tag,
with that URL, before </body>:
<img src="PIXEL_URL" alt="" width="1" height="1" border="0" style="display:block;width:1px;height:1px;border:0;overflow:hidden">
The same two steps in JavaScript, before your existing send call:
const res = await fetch('https://p.didtheyopen.com/v1/messages', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.DIDTHEYOPEN_API_KEY}`,
'Idempotency-Key': clientRef,
'Content-Type': 'application/json',
},
body: JSON.stringify({ client_ref: clientRef, sender_label: 'work', label: 'Dana Levi' }),
});
if (res.status === 201) {
const { pixel_url } = await res.json();
const tag = `<img src="${pixel_url}" alt="" width="1" height="1" border="0" style="display:block;width:1px;height:1px;border:0;overflow:hidden">`;
html = html.includes('</body>') ? html.replace('</body>', () => tag + '</body>') : html + tag;
}
// Then send html with users.messages.send or Graph sendMail, as before.
If the call does not return 201, send the email untracked. When the free trial is used up
the response is 402 payment_required with checkout links. Every endpoint and
error is in the API docs and the
OpenAPI document.
Rules for the send code
- Track every email, unless the owner says not to track one.
- Leave an existing plain-text part untouched. A plain-text-only email cannot carry a pixel: send it as HTML with the same words and keep the text as the plain-text part.
- Do not change the subject, threading headers, attachments or recipients.
- One image cannot tell people apart. For a per-person result, send one copy per recipient, each with its own pixel.
-
Wrap links with
POST /v1/messages/<id>/linksunless the owner says not to track links. A person's click in a browser counts as opened. A click fetched by Apple's relay or another mail proxy, or from an Apple or Google network with a normal browser, is labelledprefetch_likelyorunknownand not counted. - Some sending libraries strip external images. Send one test to your own address and open it in Gmail (web or app) or Outlook, not Apple Mail. Apple Mail hides opens, so that test only shows that the image arrived.
didtheyopen needs no Google or Microsoft sign-in. The tracker never sees the email or the
mail credentials, and it stores no recipient address. The one thing it keeps about the
recipient is the display label your code chooses to send, such as "Dana
Levi", and that field is optional. Your code keeps its own Gmail or Graph access.
What comes back
Each load has a time, a coarse device family and a label. Only loads labelled
opened count as opens. The automatic Apple Mail load is labelled
mpp_unknown, and loads by security software are labelled
prefetch_likely; neither is counted as an open. Gmail opens arrive through
Gmail's image proxy and are reported as "opened in Gmail." See
How accurate is email open tracking?.
Without writing the calls
The same account is a remote MCP server at
https://p.didtheyopen.com/mcp (Streamable HTTP), with
didtheyopen_track_email and didtheyopen_new_opens in place of
the HTTP calls. See the
MCP server guide and the
framework setup pages. Or give an agent this prompt and let it
do the integration:
Set up email open tracking for me with didtheyopen. Follow https://didtheyopen.com/agent.md
Price and privacy
25 tracked emails are free, with no card. Then Personal is $9/month (up to 300 tracked emails a day) or Developer is $29/month (up to 2,000 a day). No recipient addresses, subjects, content or IP addresses are stored. A tracked message and its opens are deleted after 30 days by default, or sooner if you set a shorter expiry, from when the message is created.
Questions
Does the Gmail API have open tracking?
No. The Gmail API sends the message and returns its id. It has no open event and no open-tracking option. To learn about opens, add a tracking image to the HTML body before you call users.messages.send.
Does Microsoft Graph report when a message is opened?
No. Graph sendMail has no open event. It can attach a receipt request, which asks the recipient for permission, and the recipient can decline. A tracking image needs no action from the recipient, but it only fires when their mail app loads images.
Do browser extensions such as Mailtrack track mail sent through the Gmail API?
A browser extension works where you click Send in the browser. When code or an agent sends through the Gmail API or SMTP, there is no browser in the path. Mailtrack's own pages do not describe tracking such mail.
Does didtheyopen need access to my Gmail or Microsoft account?
No. didtheyopen only issues the pixel and records loads. It needs no Google or Microsoft sign-in, and it never sees the email or the mail credentials. It stores no recipient address, only the optional display label your code chooses to send.
Can I track a plain-text message?
Not as it is. A plain-text message cannot carry an image. Send it as HTML with the same words, and keep the text as the plain-text part.
Related guides
- Email open tracking API for AI agents: every call, the webhook signature and the errors.
- How email open tracking works: the tracking pixel, step by step.
- How accurate is email open tracking?: what the load labels mean.
- Open tracking for your personal AI agent: setup inside the agent you already use.