Official scripts
Explore our curated collection of scripts
Get Current Gmail User
Return the display name and email of the Gmail account this browser is signed in as.
Search Gmail
Search the signed-in Gmail with the native query syntax (from:, to:, subject:, has:attachment, after:/before:, labels…) and return matching threads: threadId (feed it to get_thread / reply_to_email), sender, senderEmail, subject, snippet, date, unread, starred, hasAttachment. Results are threads rather than individual messages, which is Gmail's own search granularity, and only the first page of results is returned (up to 50).
Download Gmail attachments
Download every attachment of a Gmail thread, given its thread id as returned by search_emails, and save the files to your computer under their real names. Returns the thread id, how many files were saved, and each file's name and path. Attachments from every message in the thread are included, and inline images count as attachments.
List Gmail inbox
List the messages on the first page of the Gmail inbox. Requires an authenticated mail.google.com session. Returns folder, total (the range line as rendered, e.g. "1–50 of 240") and rows of sender, subject, snippet, date plus the unread / starred / hasAttachment flags. Covers only the first inbox page (up to ~50 rows as Gmail renders it); there is no pagination. Be aware that the output requires at least one row, so a genuinely empty inbox is not representable and will surface as a failure rather than an empty list.
Trash Gmail thread
Move a Gmail thread to the Bin by its hex threadId. Acts from the list view, scanning the first 4 All Mail pages (~200 newest threads), and confirms the row actually left All Mail rather than trusting a toast. Returns trashed, threadId, and the page it was found on.
Get Gmail thread
Read a Gmail thread by its hex threadId (as returned by search_emails): subject plus every rendered message's from, fromEmail, to, date, plain-text body and attachment names. In long threads Gmail collapses older messages, so only rendered (expanded) messages are returned.
Send Gmail email
Send an email from the signed-in Gmail account, with a plain-text body and an optional single file attachment.
Create a Gmail draft
Compose a Gmail message and save it as a draft without sending it. Takes to/cc/bcc, subject and body, and confirms the draft exists in Drafts afterward rather than trusting the compose window closing.
List Gmail labels / folders
List the Gmail labels and system folders visible to the account, with their unread counts where Gmail shows one. Distinguishes system folders (Inbox, Sent, Drafts, Spam, Bin...) from user-created labels.
Forward Gmail thread
Forward an entire Gmail thread to one recipient, with an optional leading note. Takes the hex threadId that search_emails returns, and forwards the whole conversation inline rather than a single message. Returns forwarded, threadId and to. The thread must be on the first page of All Mail, newest-first, so older conversations cannot be reached this way.
List Google accounts signed in on this browser (Gmail)
List the Google accounts signed in on this browser, as the Gmail account switcher shows them. Each account comes back with its address, the index that addresses it in a Google URL, and whether it is the one Gmail opens by default. The index is what the other Gmail scripts take as their account argument, so this answers which account a script acts as when none is given.
Mark Gmail thread as unread
Mark a Gmail thread as unread by its hex threadId. Returns unread, threadId, the All Mail page it was found on, and already_unread. Acts from the All Mail list, scanning the first 4 pages (~200 newest threads). Safe to repeat: a thread that is already unread returns already_unread:true without clicking anything. Waits for Gmail to persist the change rather than returning on the optimistic row restyling, so the mail really is unread once the run ends.
Mark Gmail thread as read
Mark a Gmail thread as read by its hex threadId. Returns read, threadId, the All Mail page it was found on, and already_read. Acts from the All Mail list, scanning the first 4 pages (~200 newest threads). Safe to repeat: a thread that is already read returns already_read:true without clicking anything. Waits for Gmail to persist the change rather than returning on the optimistic row restyling, so the mail really is read once the run ends.
Send a Gmail draft
Send an existing Gmail draft, identified by the id the drafts listing gives you. This delivers a real message and cannot be undone, so the draft's recipients and subject are read and reported back before and with the send, and a draft with no recipient is refused rather than attempted. Success is confirmed two ways: the draft leaves Drafts and the same conversation turns up in Sent. The conversation id is returned and is the same before and after sending, so the message can be found again afterwards.
Reply to Gmail thread
Reply (or reply-all) inside an existing Gmail conversation, given its thread id or the conversation's link, so the reply stays in the same thread with the original subject and quoted history. Optionally add Cc recipients, attach one file, or schedule the reply for later. Returns whether it was sent or scheduled, the conversation id and subject, and for scheduled replies the time Gmail shows.
Gmail whoami (signed-in account)
Report which Gmail account this browser is signed in as: display name and email, from Gmail's account switcher. Being signed out is reported as a normal answer (loggedIn false), not an error, so it can be used to check a session before running other Gmail scripts.
List Gmail drafts
List the unsent drafts in the signed-in Gmail account, each with the identifier needed to open, edit or send it, plus its subject, preview text, whether it carries an attachment, and the date Gmail shows. Gmail's own draft total is returned alongside the number of drafts read, so a mailbox with more drafts than one screenful is visible as such rather than looking complete. An account with no drafts is a normal empty result, not an error. Note that the drafts list does not show who a draft is addressed to — Gmail puts the word "Draft" where the recipient would be — so recipients have to come from opening the draft itself.
unsubscribe_from_sender
Unsubscribe from a mailing list using Gmail's own unsubscribe control, which appears beside the sender on a message carrying a List-Unsubscribe header. Returns the sender it acted on, whether the control was present, and whether Gmail confirmed the request. This leaves the mailing list for real and cannot be undone from Gmail: confirm the exact sender with the user before running, and note that approval for one sender does not carry over to another. Senders with no unsubscribe control are reported rather than acted on, and the script never falls back to reporting spam.
Report Gmail thread as spam
Report a Gmail thread as spam by its hex threadId (moves it to Spam). Requires an authenticated mail.google.com session. Works from the All Mail list view, scanning the first 4 pages (~200 newest threads), and is locale-independent. Returns reportedSpam, threadId, and the page it was found on. Moving the thread to Spam also feeds Gmail's spam classifier for that sender, which undoing does not fully reverse. Pass `account` (authuser=) in a multi-account browser jar, or Gmail picks u/0 nondeterministically. Senders with an unsubscribe link raise an extra "Report spam or unsubscribe?" dialog; the script confirms the spam branch and rejects the unsubscribe one, and throws rather than guessing on an unrecognised dialog shape.
Archive Gmail thread
Archive a Gmail thread by its hex threadId (removes it from the Inbox; it stays in All Mail). Returns archived, threadId, and the Inbox page it was found on. Acts on the thread's row in the Inbox list, scanning the first 4 Inbox pages (~200 newest threads), and confirms the row actually left the list rather than trusting a toast. If the thread is not in those pages it throws: it is then already archived (nothing to do) or older than that. It never acts from the conversation view, where Gmail's Archive control is offered whatever the thread's state and so cannot confirm anything.
Toggle Gmail thread read state
Mark a Gmail thread as read or unread by its hex threadId. Pass read:true to mark as read (default), read:false to mark as unread. Returns the final read state, threadId, the All Mail page it was found on, and already_read/already_unread flags. Acts from the All Mail list, scanning the first 4 pages (~200 newest threads). A thread already in the requested state is left alone and comes back with already_read:true or already_unread:true, so repeating the call is safe. Waits for Gmail to persist the change rather than returning on optimistic row restyling.
Gmail — Apply or remove a label on a thread
Apply a label to a Gmail thread by its hex threadId, optionally creating the label first, or take the label off again with remove:true. A thread already in the requested state is reported as a no-op without clicking. Takes a received thread — Gmail renders no conversation heading for a thread you sent to yourself, so those are refused rather than risk labelling the wrong thread.
Update a Gmail draft
Change the subject and/or body of an existing Gmail draft, identified by the id the drafts listing gives you. Whichever field you leave out keeps its current value; a field you pass replaces what was there rather than appending to it. The draft's current contents are read first, so asking for what it already says makes no change and says so. Gmail issues a draft a new id every time it is saved, so the id you passed in stops existing and the new one is returned — use that for any follow-up. The conversation id stays the same and is returned as the stable handle. Recipients are not touched by this script.
Create a Google Workspace user (Admin console)
Creates a new user in the Google Admin console (Workspace) under the domain of the given admin account: fills first/last name, primary email local-part, optional secondary (personal) email, submits with an auto-generated 16-char password, and optionally sends the native "set your password" login-instructions email to the secondary address. Returns the created email and generated password. The admin account must already be signed in to this browser, with a session recent enough that Google does not ask to confirm the password again — when it does, the script stops before touching anything and tells you to sign in once by hand.
List Outlook.com mail folders
List the signed-in Outlook.com (outlook.live.com) account's mail folders — Inbox, Junk Email, Drafts, Sent Items, Deleted Items, Archive, Conversation History, Notes and any custom folders — from the navigation pane's folder tree. Returns each folder's name and whether it's currently selected.
