client.Drafts
この名前空間のすべてのメソッドの、シグネチャ、パラメーター、戻り値、例。
メソッド
Unsent messages saved in the mailbox, each stored as a thread labelled DRAFT.
Drafts.ListAsync
List one page of drafts
Task<Page> ListAsync( string? query = null, int? limit = null, string? cursor = null, string? apiKey = null, CancellationToken cancellationToken = default)Returns one page of saved drafts, most recently saved first. A row is only object and id, so call GetAsync for recipients, subject and body. A draft is stored as a thread labelled DRAFT, so this reads the same index as Threads.ListAsync(folder: "draft").
query takes the same search syntax as Threads.ListAsync. Plain words must all appear and match loosely, ignoring case, accents and separators, against the draft's subject, its sender and the first 4,000 characters of its body with markup stripped, while a quoted phrase is matched as written apart from case and accents, so "ben jamin" does not find "Ben-Jamin". Filler words such as the or emails are dropped when something else is left to search for. Recipients are stored as one list without roles and are not written for a draft, so to:, cc: and bcc: match nothing here. subject:, body: and from: narrow the search, and after:, before:, newer_than: and older_than: read the time the draft was last saved, in UTC, with after: including the day it names and before: excluding it. A draft saved with no subject is stored as (no subject), so subject:"no subject" finds it. The drafts folder always applies, so in: and folder is: operators such as is:sent cannot widen the search beyond drafts, in:anywhere included.
The API pages with an opaque pageToken, which the SDK hands back as nextCursor and accepts as cursor:. A page holds 25 drafts unless limit: says otherwise.
パラメーター
querystring?Mailbox search over the subject, sender and body preview. Plain words must all appear and match loosely, a quoted phrase has to appear as written, filler words are dropped when something else is left to search for, and operators such as
subject:andolder_than:30dnarrow it.to:,cc:andbcc:match nothing on a draft, and the search cannot leave drafts.limitint?Drafts per page, a whole number from 1 to 100. Defaults to 25.
cursorstring?The
nextCursorof the previous page, passed back unchanged.apiKeystring?Overrides the client's API key for this call only.
cancellationTokenCancellationTokenCancels the request.
戻り値
A Page with items, hasMore and nextCursor. Each item has only object, set to draft, and id.
例
var page = await client.Drafts.ListAsync(query: "subject:proposal", limit: 20); foreach (var summary in page){ var draft = await client.Drafts.GetAsync(summary["id"]!.GetValue<string>()); Console.WriteLine($"{draft["subject"]} to {string.Join(", ", draft["to"]?.AsArray() ?? [])}");}注意事項
The server offers a cursor whenever a page comes back full, so
hasMorecan be true on the last page and the following call returns no items.Saving a draft moves it to the top, so a draft edited while you page is not returned by later pages.
A value
querycannot use is ignored rather than narrowing, so a typo in a value widens the result instead of emptying it. That coverscategory:,larger:,smaller:,size:,messagesize:,list:,rfc822msgid:,received:andsent:, the category words such asis:promotions, ahas:word naming no kind of attachment, animportance:other thanhighorlow, an unreadable date and a duration whose unit is noth,d,w,mory. An operator name it does not know,project:for instance, is searched as plain text.
ほかの提供先
- API
GET /drafts- TypeScript
drafts.list()- Python
drafts.list()- Ruby
drafts.list- PHP
drafts->list- Go
Drafts.List- Java
drafts().list- CLI
openemail drafts list
Drafts.ListAllAsync
Collect every draft into one object
Task<IReadOnlyList<JsonObject>> ListAllAsync( string? query = null, int? limit = null, string? cursor = null, string? apiKey = null, CancellationToken cancellationToken = default)Walks every page with the same query as ListAsync and returns once the last page is in, so the whole result sits in memory at once. Drafts rarely number in the thousands, which makes this the simplest way to read them all.
Each request asks for limit: drafts, 25 when you leave it out. Passing cursor: starts the walk from that page instead of the first. The walk ends when the server stops offering a cursor or hands back the one it was given, and a failure on any page throws and discards what was collected.
パラメーター
querystring?Mailbox search over the subject, sender and body preview, as in
ListAsync. Plain words must all appear and match loosely, a quoted phrase has to appear as written, filler words are dropped when something else is left to search for, and operators such assubject:andolder_than:30dnarrow it.to:,cc:andbcc:match nothing on a draft, and the search cannot leave drafts.limitint?Page size for each request, a whole number from 1 to 100. Defaults to 25.
cursorstring?A
nextCursorto start the walk from instead of the first page.apiKeystring?Overrides the client's API key for every page of this walk.
cancellationTokenCancellationTokenCancels the request.
戻り値
A list of JsonObject items, every matching draft with object set to draft and its id, most recently saved first.
例
var drafts = await client.Drafts.ListAllAsync(limit: 100); Console.WriteLine($"{string.Join(Environment.NewLine, drafts.Select(row => row?["id"]))}");注意事項
Rows are ids only. Reading each draft afterwards is one
GetAsyncper id.Each page is its own request with its own retries, so one failed attempt does not restart the walk.
ほかの提供先
- API
GET /drafts- TypeScript
drafts.listAll()- Python
drafts.list_all()- Ruby
drafts.list_all- PHP
drafts->listAll- Go
Drafts.ListAll- Java
drafts().listAll
Drafts.IterateAsync
Stream drafts one at a time across pages
IAsyncEnumerable<JsonObject> IterateAsync( string? query = null, int? limit = null, string? cursor = null, string? apiKey = null, CancellationToken cancellationToken = default)Returns an IAsyncEnumerable<JsonObject> that yields drafts one by one and requests the next page only when the current one is used up. Nothing is fetched until the loop starts, and breaking out of it stops further requests.
The cursor marks a position in save time rather than a row count, so deleting drafts inside the loop does not make the walk skip the ones after them. Updating a draft during the walk moves it to the top, and it is not yielded a second time.
パラメーター
querystring?Mailbox search over the subject, sender and body preview, as in
ListAsync. Plain words must all appear and match loosely, a quoted phrase has to appear as written, filler words are dropped when something else is left to search for, and operators such assubject:andolder_than:30dnarrow it.to:,cc:andbcc:match nothing on a draft, and the search cannot leave drafts.limitint?Page size for each request, a whole number from 1 to 100. Defaults to 25.
cursorstring?A
nextCursorto start from instead of the first page.apiKeystring?Overrides the client's API key for every page of this walk.
cancellationTokenCancellationTokenCancels the request.
戻り値
An IAsyncEnumerable<JsonObject> that yields one object per draft, each with object set to draft and id.
例
await foreach (var summary in client.Drafts.IterateAsync(query: "older_than:30d")){ var draft = await client.Drafts.GetAsync(summary["id"]!.GetValue<string>()); if ((draft["to"]?.AsArray().Count ?? 0) == 0 && (string?)draft["subject"] == "(no subject)") { await client.Drafts.DeleteAsync(draft["id"]!.GetValue<string>()); }}注意事項
The generator is lazy, so an abandoned loop costs only the pages it consumed.
ほかの提供先
- API
GET /drafts- TypeScript
drafts.iterate()- Python
drafts.iterate()- Ruby
drafts.iterate- PHP
drafts->iterate- Go
Drafts.Iterate- Java
drafts().iterate
Drafts.GetAsync
Read a draft's recipients, subject and body
Task<JsonObject> GetAsync( string id, string? apiKey = null, CancellationToken cancellationToken = default)Returns the fields a draft was saved with: to, cc, bcc, subject, the body as html, the from address, the threadId it replies to and its attachment list. The id must belong to a thread labelled DRAFT, so an ordinary thread id is a 404 here even though Threads.GetAsync opens it.
Values come back normalised rather than as sent. Recipients are bare addresses with display names dropped, an empty subject reads as (no subject), and from is the address the draft was saved with. It is reported only while the workspace can still send as the stored sender, so a draft saved from an address that has since gone reads from as null, as does a draft saved without a sender. A draft saved with text and no html returns that text in html, unconverted.
threadId is null for a draft that does not reply to anything. forwardOf is the message in threadId the draft forwards, or null. attachments carries only filename, contentType and size, because draft attachments are stored as names and types without content: a forwarding draft attaches the forwarded message's files when it is sent, and any other file goes on the send itself.
パラメーター
idstring必須Draft id, which starts with
draft-.apiKeystring?Overrides the client's API key for this call only.
cancellationTokenCancellationTokenCancels the request.
戻り値
A JsonObject with id, to, cc, bcc, subject, html, from, threadId, forwardOf and attachments, a list of objects with filename, contentType and size.
例
var draft = await client.Drafts.GetAsync("draft-5f0c2a9e-8b1d-4e7a-a3c6-2d9f41b7e0c8"); Console.WriteLine($"{draft["from"]?.ToString() ?? "no sender"} to {string.Join(", ", draft["to"]?.AsArray() ?? [])}");Console.WriteLine($"{draft["subject"]}");Console.WriteLine($"{draft["threadId"]?.ToString() ?? "starts a new conversation"}");注意事項
A draft keeps the same id through every update.
A missing draft throws an
OpenEmailApiExceptionwhoseIsNotFoundis true.
ほかの提供先
- API
GET /drafts/{id}- TypeScript
drafts.get()- Python
drafts.get()- Ruby
drafts.get- PHP
drafts->get- Go
Drafts.Get- Java
drafts().get- CLI
openemail drafts get
Drafts.CreateAsync
Save a new draft
Task<JsonObject> CreateAsync( IReadOnlyDictionary<string, object?> body, string? apiKey = null, CancellationToken cancellationToken = default)Saves an unsent message to the mailbox and returns its id. Every field is optional, so CreateAsync(new Body()) saves a blank draft. The body is strict: any key outside the fields below is a 422 invalid_parameter, and there is no field for attachments, which a send carries itself.
To forward an email, pass threadId and forwardOf, the id of a message in that thread from Threads.GetAsync. The draft takes the names of that message's files and, unless you give a subject, its subject with Fwd: in front. Sending the draft with Emails.SendAsync and its draftId then quotes the message below the body, attaches its files and threads it the way forwarding in the app does. forwardOf without threadId, or naming no message of that thread, is a 422 invalid_parameter.
Nothing is validated beyond length. Addresses in to, cc and bcc may carry a display name, as in Ada Lovelace <[email protected]>, and from is stored as given. A draft saved without from has no sender, and GetAsync reads from back as null. subject is capped at 998 characters, and html and text at 1,000,000 each. When both bodies are sent only html is kept.
threadId records the conversation the draft replies to, but the draft is stored as a thread of its own under its new id. It shows up in Threads.ListAsync(folder: "draft"), not inside the original thread.
パラメーター
toIEnumerable<string>Recipient addresses, bare or with a display name.
ccIEnumerable<string>Copy recipients, bare or with a display name.
bccIEnumerable<string>Blind copy recipients, bare or with a display name.
subjectstringAt most 998 characters. Empty is stored as
(no subject).htmlstringBody markup, at most 1,000,000 characters. Kept over
textwhen both are set.textstringBody used only when
htmlis absent, at most 1,000,000 characters. Stored as is and read back inhtml.fromstringSender address, optionally with a display name. Left out, the draft is saved with no sender.
threadIdstringId of the thread this draft replies to, or the thread holding the message
forwardOfnames.forwardOfstringId of the message in
threadIdto forward. Sending the draft quotes it below the body and attaches its files.apiKeystring?Overrides the client's API key for this call only.
cancellationTokenCancellationTokenCancels the request.
戻り値
A JsonObject with object set to draft and id, the new draft's id.
例
var draft = await client.Drafts.CreateAsync(new Body{ ["from"] = "Ada Lovelace <[email protected]>", ["to"] = new[] { "[email protected]" }, ["subject"] = "Engine notes for Thursday", ["html"] = "<p>Agenda below, comments welcome.</p>",}); Console.WriteLine($"{draft["id"]}");注意事項
The SDK does not retry a create after a network failure, because the endpoint takes no idempotency key and a second attempt saves a second draft.
A display name containing a comma splits into two broken recipients, because the lists are joined and split again on commas. Send such names without the comma.
Draft ids are
draft-followed by a UUID.
ほかの提供先
- API
POST /drafts- TypeScript
drafts.create()- Python
drafts.create()- Ruby
drafts.create- PHP
drafts->create- Go
Drafts.Create- Java
drafts().create- CLI
openemail drafts create
Drafts.UpdateAsync
Change fields on a saved draft
Task<JsonObject> UpdateAsync( string id, IReadOnlyDictionary<string, object?> body, string? apiKey = null, CancellationToken cancellationToken = default)A partial update: each field you send replaces the stored value and each field you leave out keeps it. Lists replace wholesale, so sending to with one address drops the rest. The limits and the strict body are the same as CreateAsync.
The draft must already exist. An unknown id, or the id of a thread that is not a draft, is a 404 rather than a new draft. The returned id is the one to keep using, and it is always the id you passed.
Sending text without html replaces the stored body with that text. The draft keeps its attachment list, and a draft that forwards a message keeps forwarding it unless threadId moves it to another conversation.
パラメーター
idstring必須Draft id, which starts with
draft-.toIEnumerable<string>Replacement recipients. An empty dictionary clears them.
ccIEnumerable<string>Replacement copy recipients.
bccIEnumerable<string>Replacement blind copy recipients.
subjectstringReplacement subject, at most 998 characters.
htmlstringReplacement body markup, at most 1,000,000 characters.
textstringReplacement body used only when
htmlis absent.fromstringReplacement sender. An empty string clears it, leaving the draft with no sender.
threadIdstringThread the draft replies to. An empty string detaches it.
apiKeystring?Overrides the client's API key for this call only.
cancellationTokenCancellationTokenCancels the request.
戻り値
A JsonObject with object set to draft and id, the id you passed.
例
var saved = await client.Drafts.UpdateAsync("draft-5f0c2a9e-8b1d-4e7a-a3c6-2d9f41b7e0c8", new Body{ ["to"] = new[] { "[email protected]", "[email protected]" }, ["subject"] = "Engine notes for Thursday, revised",}); var draft = await client.Drafts.GetAsync(saved["id"]!.GetValue<string>()); Console.WriteLine($"{draft["subject"]} to {string.Join(", ", draft["to"]?.AsArray() ?? [])}");注意事項
The SDK does not retry this call after a network failure. Read the draft with
GetAsyncbefore trying again.Leaving a field out keeps its stored value. An empty string clears
threadId, and an empty string or null clearsfrom.
ほかの提供先
- API
PATCH /drafts/{id}- TypeScript
drafts.update()- Python
drafts.update()- Ruby
drafts.update- PHP
drafts->update- Go
Drafts.Update- Java
drafts().update- CLI
openemail drafts update
Drafts.DeleteAsync
Delete a draft permanently
Task<JsonObject> DeleteAsync( string id, string? apiKey = null, CancellationToken cancellationToken = default)Removes the draft, its stored body and its attachment entries from the mailbox. It does not go to the Bin and there is no undo.
The id must belong to a thread carrying the DRAFT label, so an ordinary thread id is a 404. Use Threads.TrashAsync to remove real mail.
パラメーター
idstring必須Draft id, which starts with
draft-.apiKeystring?Overrides the client's API key for this call only.
cancellationTokenCancellationTokenCancels the request.
戻り値
A JsonObject with object set to draft, the id and deleted set to true.
例
var removed = await client.Drafts.DeleteAsync("draft-5f0c2a9e-8b1d-4e7a-a3c6-2d9f41b7e0c8"); Console.WriteLine($"{removed["id"]}{((bool?)removed["deleted"] == true ? " is gone" : " is still there")}");注意事項
The SDK does not retry a delete. A 404 on your own second attempt after a lost response means the first one worked.
Threads.UpdateAsyncrefusesDRAFTwith 422label_not_directly_settable, so an ordinary thread can never be turned into something this method deletes.
ほかの提供先
- API
DELETE /drafts/{id}- TypeScript
drafts.delete()- Python
drafts.delete()- Ruby
drafts.delete- PHP
drafts->delete- Go
Drafts.Delete- Java
drafts().delete- CLI
openemail drafts delete