Skip to main content
The emails resource allows you to list, read, send, reply, forward, and manage emails.

List Emails

Retrieve emails from a folder:
const { emails, total, folder, account } = await jasni.emails.list({
  account: '[email protected]',
  folder: 'INBOX',  // Optional: default is INBOX
  limit: 50,        // Optional: default is 50, max 100
})

emails.forEach(email => {
  console.log(`${email.from} - ${email.subject}`)
})

Options

ParameterTypeRequiredDescription
accountstringYesEmail account to fetch from
folderstringNoFolder to fetch from. Default: INBOX
limitnumberNoNumber of emails to fetch. Default: 50, max: 100

Response

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

interface ListEmailsResponse {
  emails: EmailPreview[]
  folder: string
  total: number
  account: string
}

Get Email

Retrieve a specific email by UID:
const { email } = await jasni.emails.get(123, {
  account: '[email protected]',
  folder: 'INBOX',  // Optional
})

console.log('Subject:', email.subject)
console.log('From:', email.from)
console.log('Body:', email.text || email.html)

Options

ParameterTypeRequiredDescription
accountstringYesEmail account
folderstringNoFolder. Default: INBOX

Response

The Email type extends EmailPreview with full content:
interface Email extends EmailPreview {
  text?: string
  html?: string
  cc?: EmailAddress[] | string[]
  bcc?: EmailAddress[] | string[]
  replyTo?: string
  attachments?: EmailAttachment[]
  inReplyTo?: string
  references?: string
}

Send Email

Send a new email:
const result = await jasni.emails.send({
  from: '[email protected]',
  to: ['[email protected]'],
  subject: 'Hello!',
  text: 'Plain text body',
  html: '<p>HTML body</p>',  // Optional
  cc: ['[email protected]'],    // Optional
  bcc: ['[email protected]'],  // Optional
  replyTo: '[email protected]', // Optional
})

console.log('Message ID:', result.messageId)

Options

ParameterTypeRequiredDescription
fromstringYesSender email (must be an account you own)
tostring | string[]YesRecipient email address(es)
subjectstringYesEmail subject
textstringNoPlain text body
htmlstringNoHTML body
ccstring | string[]NoCC recipients
bccstring | string[]NoBCC recipients
replyTostringNoReply-to address
You must provide at least text or html for the email body.

Response

interface SendEmailResponse {
  messageId: string
  from: string
  to: string[]
  subject: string
  savedToSent: boolean
}

Reply to Email

Reply to an existing email:
const reply = await jasni.emails.reply(123, {
  account: '[email protected]',
  text: 'Thanks for your email!',
  replyAll: false,         // Optional: default false
  includeOriginal: true,   // Optional: default true
})

console.log('Reply sent:', reply.messageId)

Options

ParameterTypeRequiredDescription
accountstringYesEmail account
folderstringNoFolder of the original email. Default: INBOX
textstringNoPlain text reply body
htmlstringNoHTML reply body
replyAllbooleanNoReply to all recipients. Default: false
includeOriginalbooleanNoInclude original message. Default: true

Response

interface ReplyResponse {
  messageId: string
  from: string
  to: string[]
  cc?: string[]
  subject: string
  inReplyTo: string
  references: string
  savedToSent: boolean
}

Forward Email

Forward an email to other recipients:
const forward = await jasni.emails.forward(123, {
  account: '[email protected]',
  to: ['[email protected]'],
  text: 'FYI - see below',  // Optional message
  cc: ['[email protected]'],   // Optional
})

console.log('Forwarded:', forward.messageId)

Options

ParameterTypeRequiredDescription
accountstringYesEmail account
folderstringNoFolder of the original email. Default: INBOX
tostring | string[]YesRecipients to forward to
ccstring | string[]NoCC recipients
bccstring | string[]NoBCC recipients
textstringNoMessage to include before forwarded content
htmlstringNoHTML message
includeOriginalbooleanNoInclude original message. Default: true

Response

interface ForwardResponse {
  messageId: string
  from: string
  to: string[]
  cc?: string[]
  subject: string
  savedToSent: boolean
  forwardedFrom: {
    uid: number
    from: EmailAddress | string
    subject: string
    date: string
  }
}

Delete Email

Delete an email:
await jasni.emails.delete(123, {
  account: '[email protected]',
})

Mark as Read/Unread

Update the read status of an email:
// Mark as read
await jasni.emails.markAsRead(123, { account: '[email protected]' })

// Mark as unread
await jasni.emails.markAsUnread(123, { account: '[email protected]' })

Email Labels

The SDK also provides methods to manage labels on emails. See the Labels page for details on:
  • Getting labels for an email
  • Assigning labels to an email
  • Removing labels from an email

Example: Email Workflow

Here’s a complete example of an email workflow:
import { Jasni } from 'jasni-sdk'

const jasni = new Jasni('jsk_your_api_key')

async function emailWorkflow() {
  const account = '[email protected]'
  
  // List recent emails
  const { emails } = await jasni.emails.list({
    account,
    limit: 10,
  })
  
  console.log(`Found ${emails.length} emails`)
  
  // Get the first unread email
  const unread = emails.find(e => !e.seen)
  if (unread) {
    // Get full content
    const { email } = await jasni.emails.get(unread.uid, { account })
    console.log('Subject:', email.subject)
    console.log('Body:', email.text)
    
    // Mark as read
    await jasni.emails.markAsRead(unread.uid, { account })
    
    // Reply to it
    await jasni.emails.reply(unread.uid, {
      account,
      text: 'Thank you for your email! I will get back to you soon.',
    })
  }
  
  // Send a new email
  await jasni.emails.send({
    from: account,
    to: '[email protected]',
    subject: 'Hello from SDK',
    text: 'This is a test email sent from the Jasni TypeScript SDK.',
    html: '<p>This is a test email sent from the <strong>Jasni TypeScript SDK</strong>.</p>',
  })
}

emailWorkflow().catch(console.error)