Skip to main content
The drafts resource allows you to create, list, update, and delete email drafts.

List Drafts

Retrieve all drafts for an account:
const { drafts, total, account } = await jasni.drafts.list({
  account: '[email protected]',
  limit: 50,  // Optional: default is 50
})

drafts.forEach(draft => {
  console.log(`Draft: ${draft.subject || '(No subject)'}`)
})

Options

ParameterTypeRequiredDescription
accountstringYesEmail account
limitnumberNoMaximum number of drafts. Default: 50

Response

interface Draft {
  uid: number
  messageId: string
  subject: string
  from: EmailAddress | string
  to: EmailAddress[] | string[]
  date: string
  seen: boolean
  hasAttachments: boolean
  snippet?: string
  text?: string
  html?: string
}

interface ListDraftsResponse {
  drafts: Draft[]
  total: number
  account: string
}

Create Draft

Create a new draft:
const { uid } = await jasni.drafts.create({
  account: '[email protected]',
  to: '[email protected]',
  subject: 'Draft subject',
  text: 'Draft body',
  html: '<p>Draft body</p>',  // Optional
  cc: ['[email protected]'],      // Optional
})

console.log('Draft created with UID:', uid)

Options

ParameterTypeRequiredDescription
accountstringYesEmail account
tostring | string[]NoRecipient email address(es)
subjectstringNoEmail subject
textstringNoPlain text body
htmlstringNoHTML body
ccstring | string[]NoCC recipients
All fields except account are optional when creating a draft. You can create an empty draft and update it later.

Response

interface CreateDraftResponse {
  uid: number
  account: string
  message: string
}

Update Draft

Update an existing draft:
await jasni.drafts.update({
  account: '[email protected]',
  uid: 123,
  subject: 'Updated subject',
  text: 'Updated body',
  to: ['[email protected]'],
})

Options

ParameterTypeRequiredDescription
accountstringYesEmail account
uidnumberYesUID of the draft to update
tostring | string[]NoRecipient email address(es)
subjectstringNoEmail subject
textstringNoPlain text body
htmlstringNoHTML body
ccstring | string[]NoCC recipients

Response

interface UpdateDraftResponse {
  uid: number
  account: string
  message: string
}

Delete Draft

Delete a draft:
await jasni.drafts.delete({
  account: '[email protected]',
  uid: 123,
})

Options

ParameterTypeRequiredDescription
accountstringYesEmail account
uidnumberYesUID of the draft to delete

Example: Draft Workflow

Here’s a complete example of working with drafts:
import { Jasni } from 'jasni-sdk'

const jasni = new Jasni('jsk_your_api_key')

async function draftWorkflow() {
  const account = '[email protected]'
  
  // Create a new draft
  const { uid } = await jasni.drafts.create({
    account,
    to: '[email protected]',
    subject: 'Important message',
    text: 'Hello, I wanted to discuss...',
  })
  console.log('Created draft:', uid)
  
  // List all drafts
  const { drafts } = await jasni.drafts.list({ account })
  console.log(`Total drafts: ${drafts.length}`)
  
  // Update the draft
  await jasni.drafts.update({
    account,
    uid,
    subject: 'Very important message',
    text: 'Hello, I wanted to discuss something urgent...',
  })
  console.log('Updated draft')
  
  // Later, when ready to send, you can:
  // 1. Get the draft content
  // 2. Send it as an email
  // 3. Delete the draft
  
  const draft = drafts.find(d => d.uid === uid)
  if (draft) {
    await jasni.emails.send({
      from: account,
      to: '[email protected]',
      subject: draft.subject,
      text: draft.text,
    })
    
    await jasni.drafts.delete({ account, uid })
    console.log('Draft sent and deleted')
  }
}

draftWorkflow().catch(console.error)