Twitter (X) to Email: Get New Posts as Alerts or a Daily Digest

By TwitterAPI.io Team•14 min read
Diagram of two Twitter to email pipelines: per-post alerts (poll or push, dedupe, send one email per post) and a daily digest (one search, render HTML, send one email)
Two inbox shapes from the same X data: about 9.6 alert emails a day for three accounts, or one digest with a median of 9 posts. Study collected in 2026.
TL;DR
  • Two shapes. Per-post alerts (one email per post, seconds to minutes late) or a daily digest (one email, all posts since yesterday). For @NWS, @NASA and @SpaceX together that is about 9.6 emails a day vs 1.
  • Digest size is small. One combined daily digest held a median of 9 posts and 9,252 bytes (max 29 posts, 25,333 bytes) across 43 days, rendered locally with Python's EmailMessage.
  • Fetch once a day. One /twitter/tweet/advanced_search call with since_time: pays only for the posts returned: median $0.00135 a day, $0.043 per 30 days for three accounts.
  • Alerts cost the empty checks. A 60-second poll costs $6.48 per 30 days and a 5-minute poll $1.30; 99.4% of 60-second checks return nothing (15-credit minimum each).
  • Measured delay. Polling a Latest search about every 13 s, new posts first appeared a median 14.2 s after their createdAt (p90 22.0 s), wait for the next poll included.
  • Sending. smtplib.SMTP_SSL on port 465 with a Google app password (needs 2-Step Verification); Google Workspace caps a user at 2,000 messages a day, so a digest stays far inside it.

"Twitter to email" means getting new posts from specific X accounts delivered to your inbox. It is the email sibling of our Twitter to SMS guide: that page sends one text per post and spends its effort on SMS segments and per-message carrier prices, while email is close to free to send and has room for a whole day of posts, so the real decision here is a different one: one email per post, or one digest a day. This page builds both in Python, measures how big a digest actually gets for three real organization accounts, and prices the API reads for each pattern.

The hosted recipes decide these things for you. An automation service such as IFTTT offers an "add to daily email digest" action for X triggers, and its own integration page says X trigger checks run every hour on the free plan, every 15 minutes on Starter and every 5 minutes on Pro and Pro+. Building it yourself means you choose the accounts, the filters (reposts in or out), the send time, the template and the polling interval, and you see exactly what each choice costs.

Everything quantitative on this page comes from a study we ran: 476 recent posts from @NWS, @NASA and @SpaceX, collected in 2026, turned into real daily digest emails with Python's email package and measured in bytes (nothing was sent), plus a short timing probe of how quickly a new post shows up in a polled search. The method and its limits are in the last section.

Emails a day: per-post alerts vs one digest

@NWS, @NASA and @SpaceX post about 9.6 times a day together (476 posts, collected in 2026). One daily digest held a median of 9 posts in 9,252 bytes, and its API reads cost $0.043 per 30 days vs $6.48 for 60-second alert polling.

01 — Section

Per-post alert or daily digest: which one you want

Both shapes use the same data source and the same sender. What differs is when you fetch, how many emails land, and what you pay for the reads.

Per-post alertDaily digest
Emails a day (3 accounts, measured)about 9.61
Delay after a postseconds to the poll intervalup to 24 hours
API reads per 30 days$1.30 (5 min) to $6.48 (60 s)$0.043
Runs asa loop or a webhook receiverone cron job a day

Choose alerts when a post is time-sensitive: a weather warning, a launch scrub, an outage notice from a vendor's status account, a competitor announcing pricing. Ten emails a day is fine for a dedicated mailbox or a filter label; it gets noisy in a personal inbox.

Choose a digest when you want to keep up without being interrupted: a team that follows a dozen industry accounts, a researcher tracking agencies, a founder watching competitors. A digest also lets you sort, group by account and drop reposts before anyone reads it.

Many setups end up with both: alerts for two or three accounts that matter right now, and a digest for everything else. The scripts below share their fetch and render code, so running both costs little extra effort.

02 — Section

What you need: an API key and an SMTP login

A TwitterAPI.io key. Reads need no X account and no X developer app. Sign up, copy the key from the dashboard, and new accounts that pass the automatic bot check get free starter credits (no card, one per person or network, expiring after 31 days); the amount is on the pricing page. Reads are billed at 15 credits per tweet returned, $0.15 per 1,000 tweets, with a 15-credit minimum per request.

A way to send email. Python's standard library is enough. smtplib.SMTP_SSL connects on port 465 (its documented default_port), login() authenticates, and send_message() takes an EmailMessage and fills sender and recipients from its headers; per the Python docs, a Bcc header is never transmitted.

For Gmail, an app password. Google describes an app password as a 16-digit passcode that lets an app sign in to your account, and it only works on accounts with 2-Step Verification turned on. Google also says the option may be missing on work or school accounts, on accounts protected only by security keys, and with Advanced Protection; in those cases use your organization's SMTP relay or an email API instead.

Sending limits. Google Workspace documents a daily sending limit of 2,000 messages per user account (500 on trial accounts) and 2,000 recipients per message, of which no more than 500 external. A daily digest to a handful of people uses a tiny fraction of that; per-post alerts to a large list do not, which is the point where a transactional email API is the right tool.

Somewhere to run it. A digest is one short job a day: cron on any always-on machine, a scheduled cloud function, or a scheduled CI job. Alerts need either a loop that keeps running or a public HTTPS endpoint for the webhook path.

03 — Section

The efficient fetch is a single /twitter/tweet/advanced_search call that names every account and starts at your last run: from:NWS OR from:NASA OR from:SpaceX since_time:<unix> with queryType=Latest. The response has a top-level tweets[], plus has_next_page and next_cursor when there are more than 20 results.

Because search bills per tweet returned, a quiet day costs the 15-credit minimum and a busy day costs exactly its posts. In our sample the combined day ranged from 0 to 29 posts, so the day's fetch cost between $0.00015 and $0.00435.

The alternative, one /twitter/user/last_tweets page per account, returns the latest 20 posts of each account whatever their age, so you pay for 20 tweets per account even on a quiet day: $0.009 a day for three accounts ($0.27 per 30 days) instead of a median $0.00135. Use last_tweets when you need one account's history; use the search for a recurring digest.

Keep a small state file with the IDs you already emailed and the time of the last run. Start each fetch a few minutes before the last run and drop IDs you have seen: an overlap with dedupe is safer than a gap if the job starts late.

bash
curl -G "https://api.twitterapi.io/twitter/tweet/advanced_search" \
  -H "X-API-Key: $TWITTERAPI_IO_KEY" \
  --data-urlencode "query=from:NWS OR from:NASA OR from:SpaceX since_time:1767225600" \
  --data-urlencode "queryType=Latest"
04 — Section

Step 2: render the digest as HTML and send it

Build the message with email.message.EmailMessage: set_content() for a plain-text part and add_alternative(..., subtype="html") for the HTML part, so clients that block HTML still show the posts. Escape the post text with html.escape() before putting it in the template; posts contain <, & and quotes.

A digest row needs the handle, the time, the text and a link built from the tweet's url field. Engagement counts (likeCount, retweetCount) are cheap context. If you want a thumbnail, extendedEntities.media[0].media_url_https is the image; remote images in email are often blocked until the reader allows them, so the text should stand on its own.

Reposts are worth a decision. In our sample 60.9% of @NWS posts and 46.9% of @NASA posts were reposts, against 8.1% for @SpaceX. Dropping them (retweeted_tweet is set on a repost) cuts the digest for some accounts by half; keeping them shows what the account chose to amplify.

The full script is in the code block at the end of this page. We ran its render step offline on the committed timelines (no API call, no email sent) and it produced a valid multipart message; the fetch half uses the same endpoint and fields as our study.

Bar chart of posts per full UTC day for @NWS, @NASA and @SpaceX: NWS and NASA median 3 a day, SpaceX median 1 with a peak of 22 posts in one day
Posts per full UTC day: @NWS median 3 (max 9), @NASA median 3 (max 10), @SpaceX median 1 (max 22). Collected in 2026.
05 — Section

How big a real digest gets: 476 posts from three organization accounts

We pulled the recent timelines of @NWS, @NASA and @SpaceX, grouped the posts by UTC calendar day, rendered each day as the HTML-plus-text digest from Step 2, and measured the encoded message in bytes. Nothing was sent; the size is what EmailMessage.as_bytes() returns.

AccountPosts a day (avg)Posts per day: median / maxEmpty daysMedian digest size
@NWS3.53 / 98 of 434,183 bytes
@NASA2.93 / 108 of 553,687 bytes
@SpaceX3.21 / 2216 of 483,969 bytes
All three, one email9.69 / 291 of 439,252 bytes

A digest is small. The combined daily email had a median of 9,252 bytes and peaked at 25,333 bytes on the busiest day. Images are linked, not attached, which keeps it that size; attaching photos would multiply it.

Averages hide bursts. @SpaceX averaged 3.2 posts a day but posted on a median of only 1 per day, was silent on 16 of 48 days, and put out 22 posts on its busiest day. A per-post alert for that account is quiet for days and then sends twenty emails; a digest absorbs the burst into one message.

Alert emails are tiny. A single-post alert rendered the same way had a median of 1,320 bytes, and a subject of the form New post from @handle: <first 60 characters> came to a median of 84 characters, long enough that mobile clients cut it; put the handle first so the cut keeps the useful part.

Empty days happen. Decide whether an empty day sends a "no new posts" email or nothing. Our script sends nothing, which also means a broken job and a quiet day look the same; log each run so you can tell them apart.

06 — Section

Per-post alerts: poll or push, and how fast they arrive

Polling. Run the Step 1 search in a loop with a fixed interval and since_time set to the last pass, email each new ID, and remember it. It needs nothing but outbound HTTPS. The cost is set by the empty checks, covered in the next section.

Push with a filter rule. Create a rule with POST /oapi/tweet_filter/add_rule (tag, value such as from:NWS OR from:NASA OR from:SpaceX, interval_seconds), then switch it on with POST /oapi/tweet_filter/update_rule and is_effect: 1; per the docs a new rule starts inactive. The API reference lists tag and value at up to 255 characters each and interval_seconds up to 86,400. Matching posts are pushed to the webhook URL you register in the TwitterAPI.io dashboard, and your receiver sends the email.

A receiver should acknowledge the push immediately and send the email from a background worker, so a slow SMTP login never holds up the response. The Twitter webhooks guide covers the push payload and testing it before you point it at a mailbox.

Fixed account lists. If you want posts from a stable list of accounts pushed within seconds on a flat monthly plan, Twitter Stream monitors accounts (/oapi/x_user_stream/add_user_to_monitor_tweet) and delivers to the same kind of receiver.

We did not send email, so we cannot report inbox delivery times, and we did not run a 24-hour alert job. What we measured is the API leg: we ran a Latest search for a busy generic query 12 times at a fixed pace (a median of 12.9 seconds between polls) and, for each post that appeared for the first time after the first poll, took the time our response arrived minus the post's createdAt.

MeasureSeconds
New posts observed39 posts
Median, createdAt to first returned14.2
90th percentile22.0
Fastest / slowest5.7 / 26.6

These figures include the wait for the next poll, which alone averages about half the interval, so they are an upper bound on how long a post takes to become searchable. With the posts' createdAt at one-second resolution, the fastest case of 5.7 seconds is a fair floor for this method.

From the interval math. A loop polling every 60 seconds adds an average of 30 seconds and at worst 60 to that; a 5-minute loop adds 2.5 minutes on average and at worst 5. A daily digest is, by design, up to 24 hours behind. The email leg (SMTP handoff, the recipient's spam filtering, the mail client's refresh) comes on top and depends on the providers, not on the API.

python
import os
import requests

BASE = "https://api.twitterapi.io"
H = {"X-API-Key": os.environ["TWITTERAPI_IO_KEY"]}

# 1. create the rule (it starts switched off)
r = requests.post(f"{BASE}/oapi/tweet_filter/add_rule", headers=H, json={
    "tag": "email-alerts",
    "value": "from:NWS OR from:NASA OR from:SpaceX",
    "interval_seconds": 60,
}, timeout=30).json()
rule_id = r["rule_id"]

# 2. switch it on
requests.post(f"{BASE}/oapi/tweet_filter/update_rule", headers=H, json={
    "rule_id": rule_id, "tag": "email-alerts",
    "value": "from:NWS OR from:NASA OR from:SpaceX",
    "interval_seconds": 60, "is_effect": 1,
}, timeout=30)


# Per-post alert: a webhook receiver for a TwitterAPI.io filter rule that emails each new post.
# The rule (/oapi/tweet_filter/add_rule, then update_rule with is_effect=1) pushes matching posts here.
import os
import queue
import smtplib
import threading
from email.message import EmailMessage

from flask import Flask, request

app = Flask(__name__)
jobs = queue.Queue()
seen = set()


@app.post("/x-webhook")
def receive():
    body = request.get_json(silent=True) or {}
    for t in body.get("tweets") or []:
        if t["id"] not in seen:
            seen.add(t["id"])
            jobs.put(t)
    return "", 200          # answer at once; the email goes out from the worker


def worker():
    while True:
        t = jobs.get()
        msg = EmailMessage()
        msg["From"], msg["To"] = os.environ["SMTP_USER"], os.environ["MAIL_TO"]
        msg["Subject"] = f"New post from @{t['author']['userName']}: {(t.get('text') or '')[:60]}"
        msg.set_content(f"{t.get('text') or ''}\n\n{t['url']}")
        with smtplib.SMTP_SSL("smtp.gmail.com", 465) as smtp:
            smtp.login(os.environ["SMTP_USER"], os.environ["SMTP_PASS"])
            smtp.send_message(msg)


threading.Thread(target=worker, daemon=True).start()
Histogram of seconds from a post's createdAt to the poll that first returned it, median 14.2 seconds, polling about every 13 seconds
39 new posts, polled about every 13 s: median 14.2 s from createdAt to first returned, wait for the next poll included. Collected in 2026.
07 — Section

What each pattern costs: digest vs 5-minute vs 60-second alerts

We replayed the 476 posts through four fetch patterns and priced them with the live rate card: 15 credits per tweet returned and at least 15 credits per request ($0.00015), with $1 = 100,000 credits.

PatternRequests a dayAPI cost per 30 days
Digest: 1 search a day, all three accounts1 (2 on a day over 20 posts)$0.043
Digest: 1 last_tweets page per account3$0.27
Alerts: 1 search every 5 minutes288$1.30
Alerts: 1 search every 60 seconds1,440$6.48

For alerts, the posts themselves are a rounding error: 99.4% of 60-second checks and 96.9% of 5-minute checks found nothing, and each empty check still costs the minimum. That is why the 60-second figure matches the general polling floor of $6.48 a month. Combining accounts into one from:a OR from:b query is what keeps it there; polling three accounts separately triples the floor.

Against the official X API. X's pay-per-usage rate card at docs.x.com/x-api/getting-started/pricing lists $0.005 per post read and $0.010 per user read, capped at 3 million post reads per monthly billing cycle. For returned posts that is $5 per 1,000 against $0.15 per 1,000 here, about 33x. X also offers $20 in API credits for saving a first payment card and buying credits, plus a match of the first auto-recharge up to $50.

Sending is a separate line. A Gmail or Google Workspace account sends within Google's own sending limits as part of the account; a transactional email API bills per message on its own rate card, which you should read on that provider's site.

Horizontal bar chart of 30-day API cost for three accounts: daily digest search $0.043, daily last_tweets pages $0.27, 5-minute polling $1.30, 60-second polling $6.48
API reads per 30 days for @NWS, @NASA and @SpaceX: $0.043 for a daily digest search vs $6.48 for 60-second alert polling. Collected in 2026.
08 — Section

Troubleshooting a Twitter to email job

SMTPAuthenticationError with Gmail. You are using your account password, or the account has no 2-Step Verification. Create an app password and use it as SMTP_PASS; if the option is missing, Google's help page lists the account types where it is not offered.

The digest is empty every day. Print the query string. A typo in a handle or a since_time in milliseconds instead of seconds returns no posts and costs the minimum per call. Run the curl from Step 1 with a since_time a week back to confirm the query matches.

Duplicate posts across days. The overlap window is doing its job; the ID set is what removes them. Make sure the state file is written after a successful send, not before, and that it survives restarts (a container's temporary disk does not).

Emails land in spam. Send from a domain you control with SPF and DKIM set up, or from your own Gmail to yourself while testing.

HTTP 400 from the API. The error text is in detail for a missing or invalid parameter, and in msg for other errors; log both. An unknown user in /twitter/user/info returns HTTP 200 with status: "error", not 404.

Want it without code? The n8n Twitter API workflow runs the same search on a schedule and hands the posts to n8n's email node, and the Twitter to RSS guide turns accounts into a feed that many readers can email you.

09 — Section

How we collected this

Question. How many posts would a daily Twitter-to-email digest hold for typical organization accounts, how large is that email, what do per-post alerts cost compared to a digest, and how quickly does a new post appear in a polled search?

Accounts and window. @NWS, @NASA and @SpaceX, all organization accounts. We fetched up to 8 pages of each recent timeline with /twitter/user/last_tweets (default, replies excluded), 476 posts in total, covering 44.2, 56.0 and 49.5 days respectively. Collected in 2026.

Method. Posts were grouped by UTC calendar day; partial first and last days were dropped. Each day became a digest built with Python's email.message.EmailMessage (plain text plus HTML, images linked) and was measured with as_bytes(). Costs replay each post's createdAt through 60-second and 5-minute windows and through a once-a-day search, at 15 credits per tweet returned with a 15-credit minimum per request. The delay probe ran 12 Latest searches on a generic English query at a fixed pace. The whole study used 36 requests, no more than $0.108 in API reads.

What it cannot show. Three accounts are not every account: a news outlet can post hundreds of times a day, which changes the digest size and the alert count but not the method. We sent no email, so inbox arrival times, spam placement and client rendering are not measured. The delay probe is a short sample of one query, not a 24-hour run.

Privacy. Aggregates only. The organization timelines are kept as compressed raw files; the delay-probe search results came from private individuals and were discarded after extracting second offsets, with no IDs, text or authors kept.

python
"""Twitter (X) to email: one daily digest of new posts from a few accounts.
Run once a day from cron. Fetch: one advanced_search call (plus pages if the day was busy).
Send: smtplib over SSL. Set DRY_RUN=1 to write digest.eml instead of sending."""
import html
import json
import os
import smtplib
import time
from email.message import EmailMessage

import requests

BASE = "https://api.twitterapi.io"
HEADERS = {"X-API-Key": os.environ["TWITTERAPI_IO_KEY"]}
ACCOUNTS = ["NWS", "NASA", "SpaceX"]
STATE = "digest_state.json"          # remembers the ids already emailed
SMTP_HOST, SMTP_PORT = "smtp.gmail.com", 465
SMTP_USER = os.environ.get("SMTP_USER", "")
SMTP_PASS = os.environ.get("SMTP_PASS", "")   # a Google app password, not your login password
MAIL_TO = os.environ.get("MAIL_TO", SMTP_USER)


def fetch_since(since_unix):
    query = " OR ".join(f"from:{a}" for a in ACCOUNTS) + f" since_time:{since_unix}"
    tweets, cursor = [], ""
    while True:
        params = {"query": query, "queryType": "Latest"}
        if cursor:
            params["cursor"] = cursor
        r = requests.get(f"{BASE}/twitter/tweet/advanced_search", headers=HEADERS, params=params, timeout=30)
        r.raise_for_status()
        body = r.json()
        tweets += body.get("tweets") or []
        if not body.get("has_next_page") or not body.get("next_cursor"):
            return tweets
        cursor = body["next_cursor"]
        time.sleep(1)                # fixed pacing between pages


def render(tweets):
    tweets = sorted(tweets, key=lambda t: time.mktime(time.strptime(t["createdAt"], "%a %b %d %H:%M:%S %z %Y")))
    rows = "".join(
        '<tr><td style="padding:12px 0;border-bottom:1px solid #eee">'
        f'<div style="color:#555;font-size:12px">@{html.escape(t["author"]["userName"])} &middot; {html.escape(t["createdAt"])}</div>'
        f'<div style="font-size:14px;line-height:1.5;white-space:pre-wrap">{html.escape(t.get("text") or "")}</div>'
        f'<div style="font-size:12px"><a href="{html.escape(t["url"])}">Open on X</a> &middot; {t.get("likeCount", 0)} likes</div>'
        "</td></tr>" for t in tweets)
    msg = EmailMessage()
    msg["From"], msg["To"] = SMTP_USER or "digest@example.com", MAIL_TO or "you@example.com"
    msg["Subject"] = f"X digest: {len(tweets)} new posts from {', '.join('@' + a for a in ACCOUNTS)}"
    msg.set_content("\n\n".join(f"@{t['author']['userName']} {t['createdAt']}\n{t.get('text') or ''}\n{t['url']}" for t in tweets))
    msg.add_alternative(f'<html><body style="font-family:Arial,sans-serif"><table width="600">{rows}</table></body></html>', subtype="html")
    return msg


def main():
    state = json.load(open(STATE)) if os.path.exists(STATE) else {"seen": [], "last_run": int(time.time()) - 86400}
    seen = set(state["seen"])
    now = int(time.time())
    new = [t for t in fetch_since(state["last_run"] - 300) if t["id"] not in seen]   # 5-minute overlap, deduped by id
    new = [t for t in new if not t.get("retweeted_tweet")]                             # skip reposts; drop this line to keep them
    if new:
        msg = render(new)
        if os.environ.get("DRY_RUN"):
            open("digest.eml", "wb").write(msg.as_bytes())
            print(f"wrote digest.eml: {len(new)} posts, {len(msg.as_bytes()):,} bytes")
        else:
            with smtplib.SMTP_SSL(SMTP_HOST, SMTP_PORT) as smtp:
                smtp.login(SMTP_USER, SMTP_PASS)
                smtp.send_message(msg)
            print(f"sent digest: {len(new)} posts")
    else:
        print("no new posts, no email")
    seen |= {t["id"] for t in new}
    json.dump({"seen": sorted(seen)[-5000:], "last_run": now}, open(STATE, "w"))


if __name__ == "__main__":
    main()

Researching this?Free starter credits cover end-to-end testing — Google sign-in, no card. Get a key.

10 — Questions

Questions readers ask

Can I get an email every time a specific Twitter (X) account posts?

Yes. Poll /twitter/tweet/advanced_search with from:<handle> every minute or so, or create a filter rule that pushes matching posts to a webhook receiver, and send each new post with smtplib or an email API. For @NWS, @NASA and @SpaceX together that came to about 9.6 emails a day in our study.

How do I get a daily email digest of tweets?

Run one job a day that searches from:a OR from:b since_time:<yesterday>, renders the posts into an HTML email with Python's EmailMessage, and sends it. The script on this page does exactly that and keeps a state file so no post is sent twice.

Can I send tweets to Gmail?

Yes. Send through smtp.gmail.com on port 465 with smtplib.SMTP_SSL and a Google app password. App passwords need 2-Step Verification and are not offered on some work, school or Advanced Protection accounts; use your organization's relay or an email API there.

How much does a Twitter to email digest cost to run?

The API reads are billed at 15 credits per tweet returned with a 15-credit minimum per request. One daily search for three organization accounts cost a median $0.00135 a day, about $0.043 per 30 days. Sending through your own Gmail account adds no API charge.

How fast are per-post email alerts?

In our probe, polling about every 13 seconds, new posts first came back a median 14.2 seconds after createdAt (p90 22.0 s), wait for the next poll included. A 60-second loop adds about 30 seconds on average; the email delivery leg is on top and depends on the mail providers.

Can I use IFTTT instead of code?

Yes, IFTTT has an add-to-daily-email-digest action for X triggers. Its integration page says X trigger checks run every hour on the free plan, every 15 minutes on Starter and every 5 minutes on Pro and Pro+, and its search trigger is limited to 10 tweets per check. Building it yourself gives you your own filters, template and interval.

Do I need an X developer account to email myself tweets?

No. The reads on this page go through TwitterAPI.io with an X-API-Key header; no X account or X developer app is involved. The official X API is the alternative at $0.005 per post read on its pay-per-usage rate card.

Should the digest include reposts?

It depends on the account. In our sample 60.9% of @NWS posts and 46.9% of @NASA posts were reposts, but only 8.1% of @SpaceX posts. Skip posts where retweeted_tweet is set to keep only what the account wrote.

11 — Further reading

Continue

Sources & further reading
More from this series

Writing about something you built with TwitterAPI.io? Our community rewards program pays API credits for honest tutorials, build logs and videos.

Build it

Stop reading. Start building.

Starter credits cover real testing on real data. Google sign-in, no card, no application queue.

Get an API key

Already building with TwitterAPI.io? Publish an honest tutorial or build log about it and earn up to $200 a month in API credits.