Skip to main content

Overview

Jasni makes it easy to send and receive emails on behalf of your AI agents. This guide covers the fundamentals of email operations.

Sending Emails

To send an email, use the emails.send endpoint. You can send plain text, HTML, or both.
import { Jasni } from 'jasni-sdk'

const jasni = new Jasni('jsk_your_api_key')

const result = await jasni.emails.send({
  from: '[email protected]',
  to: '[email protected]',
  subject: 'Hello from your AI agent',
  text: 'This is a plain text message.',
  html: '<p>This is an <strong>HTML</strong> message.</p>'
})

console.log('Email sent:', result.messageId)

Sending to Multiple Recipients

You can send to multiple recipients by providing an array:
await jasni.emails.send({
  from: '[email protected]',
  to: ['[email protected]', '[email protected]'],
  cc: ['[email protected]'],
  bcc: ['[email protected]'],
  subject: 'Team Update',
  text: 'Hello team!'
})

Adding Attachments

Include attachments with your emails:
await jasni.emails.send({
  from: '[email protected]',
  to: '[email protected]',
  subject: 'Report attached',
  text: 'Please find the report attached.',
  attachments: [
    {
      filename: 'report.pdf',
      content: base64EncodedContent,
      contentType: 'application/pdf'
    }
  ]
})

Receiving Emails

Listing Emails

Retrieve emails from an inbox:
const { emails, pagination } = await jasni.emails.list({
  account: '[email protected]',
  folder: 'INBOX',
  limit: 20,
  unreadOnly: true
})

for (const email of emails) {
  console.log(`From: ${email.from}`)
  console.log(`Subject: ${email.subject}`)
  console.log(`Date: ${email.date}`)
}

Getting a Specific Email

Retrieve the full content of a single email:
const email = await jasni.emails.get({
  account: '[email protected]',
  messageId: '<[email protected]>'
})

console.log('Body:', email.text || email.html)
console.log('Attachments:', email.attachments?.length || 0)

Real-Time Email Reception

For instant notifications when emails arrive, use webhooks:
const webhook = await jasni.webhooks.create({
  url: 'https://your-server.com/incoming-email',
  events: ['email.received'],
  description: 'Incoming email handler'
})
See the Webhooks Overview for detailed information on setting up real-time notifications.

Replying to Emails

Reply to an existing email thread:
await jasni.emails.reply({
  account: '[email protected]',
  messageId: '<[email protected]>',
  text: 'Thank you for your message. I will look into this.',
  html: '<p>Thank you for your message. I will look into this.</p>'
})

Forwarding Emails

Forward an email to another recipient:
await jasni.emails.forward({
  account: '[email protected]',
  messageId: '<[email protected]>',
  to: '[email protected]',
  text: 'FYI - see the email below.'
})

Best Practices

Some email clients don’t render HTML. Providing both ensures your message is readable everywhere.
Instead of polling for new emails, set up webhooks to receive instant notifications when emails arrive.
Implement exponential backoff when you encounter rate limit errors (429 status code).
Always validate email addresses before sending to avoid bounces and protect your sender reputation.

Next Steps