SDK
Drafts
`drafts.list`, `listAll`, `iterate`, `get`, `create`, `update` and `delete`.
Every method
const page = await openemail.drafts.list({ query: 'invoice', limit: 25 })const draft = await openemail.drafts.get('draft_…') const created = await openemail.drafts.create({ to: ['[email protected]'], cc: [], bcc: [], subject: 'Your September invoice', html: '<p>Draft body.</p>', from: '[email protected]', threadId: 'thread_…',}) const updated = await openemail.drafts.update(created.id!, { subject: 'Revised' })await openemail.drafts.delete(updated.id!)update keeps the draft's id, so the value it answers with is always the one you passed. An unknown id is a 404 rather than a new draft.
list pages the way threads.list does: the API’s pageToken comes back as nextCursor and goes in as cursor, and listAll and iterate follow it for you.
To send a draft, pass its id to emails.send. The draft supplies the content and the send supplies the envelope.
await openemail.emails.send({ from: '[email protected]', to: '[email protected]', draftId: 'draft_…',})Parameters: drafts.create and drafts.update (DraftInput)
tostring[]- Recipient addresses as plain strings, not the `RecipientInput` forms `emails.send` accepts, because this endpoint joins the array into the comma-separated list the driver wants. On create an omitted array saves as empty; on update an omitted field leaves the stored recipients alone, since the handler reads the draft first and merges.
ccstring[]- Cc addresses, in the same plain-string form as `to`. Empty on create when omitted, and untouched on update when omitted.
bccstring[]- Bcc addresses, in the same plain-string form as `to`. Empty on create when omitted, and untouched on update when omitted.
subjectstring- The draft's subject, at most 998 characters, the RFC 5322 line limit. On create it defaults to an empty string, so a draft always has one.
htmlstring- The draft body as markup, at most 1,000,000 characters. It is the body that wins: `html` and `text` feed the driver's single message field, so sending both stores this one.
textstring- A plain-text body, at most 1,000,000 characters, used only when `html` is absent. The draft stores one body rather than two parts, so text supplied here comes back on `html` when the draft is read.
fromstring- The sender address to save on the draft. On update it is carried through from the stored draft when omitted. The driver rebuilds the whole message from what it is handed, so a partial patch that dropped it would silently change the chosen sender.
threadIdstring- Attach the draft to an existing thread so it saves as a reply. Like `from`, it is carried through on update when omitted, because rebuilding the message without it would detach the reply from its thread.
Response: DraftResource (drafts.get)
object'draft'- Always `draft`.
idstring- The draft's id. Writes answer with a `SavedDraftResource` rather than a whole draft, so read the id off the result instead of reusing the one you sent.
tostring[]- The recipient addresses as the draft stored them. An empty array, never null, when the draft has none.
ccstring[]- Cc addresses as stored. An empty array, never null, when the draft has none.
bccstring[]- Bcc addresses as stored. An empty array, never null, when the draft has none.
subjectstring- The stored subject, or an empty string where the draft has none. This field is never null, so check its length rather than its presence.
htmlstring- The stored body, or an empty string where the draft has none. There is no separate text field on the way out: a draft saved with `text` alone is returned here.