Skip to content

Sandbox ​

Test your Conversations integration without real recipients. Send an email with captureReplies: true to the test address success@simulator.amazonses.com, then create replies to it whenever you need them.

All examples assume you've set the API key in the constructor. For multi-tenant usage, pass { apiKey } as the last argument to any method. See Configuration.

Simulate a Reply ​

ts
const sent = await outbound.email.send({
  toEmail: 'success@simulator.amazonses.com',
  fromEmail: 'admissions@yourcompany.com',
  emailSubject: 'Your application',
  htmlBody: '<p>Hi, reply to this email with any questions.</p>',
  captureReplies: true,
});

const result = await outbound.sandbox.simulateReply({
  messageId: sent.messageId!,
  text: 'Yes! What are the fees?',
});

const { thread, messages } = await outbound.conversations.getThread(result.threadId);

A simulated reply goes through the same processing as a real one. It is added to a conversation and classified, a reply is checked for requests to stop, and it fires the reply or auto_reply webhook with details.simulated: true. Its conversation and messages carry simulated: true, and you can filter on them with listThreads({ simulated: true }).

Some things never happen for simulated replies:

  • They are never added to your suppression list, even with autoSuppressOptOuts on. A request to stop is only flagged.
  • They do not count toward campaign reply totals or engagement scores.
  • Simulated conversations are deleted 30 days after their last message.

Parameters ​

FieldTypeRequiredDescription
messageIdstringYesThe messageId of an email sent with captureReplies: true to success@simulator.amazonses.com
textstringNoPlain-text body. Default 'This is a simulated reply.'. Cut off after 20,000 characters
htmlstringNoHTML body. Cut off after 200,000 characters
subjectstringNoDefault Re: <original subject>
fromEmailstringNoWho the reply comes from. Defaults to the address the email was sent to. Must be a sandbox test address such as success@simulator.amazonses.com. Use a different test address to simulate a reply from someone else, recorded as participant: 'external'
type'reply' | 'auto_reply'Noauto_reply sends the reply as an automatic one, like an out-of-office message. Default 'reply'

Response ​

ts
{
  simulated: true,
  threadId: '0199f1c2-5a4e-7c1d-9a3b-2f6e8d4c1a10',
  replyId: '0199f1c3-1d2e-7a4b-9c8d-6e5f4a3b2c1d',
  kind: 'reply'
}
FieldDescription
simulatedAlways true
threadIdThe conversation the reply was added to. Pass it to conversations.getThread()
replyIdID of the new message in the conversation
kindHow the reply was classified, usually reply or auto_reply. See Message Kinds

Possible Errors ​

ErrorStatusCause
BadRequestError400messageId is missing, type is not reply or auto_reply, text or html is not a string, or fromEmail is not a sandbox test address
ForbiddenError403Conversations is not enabled for your account
NotFoundError404No email with this messageId for your account
OutboundError422The email was not sent to a sandbox test address, was not sent with captureReplies: true, has not been sent yet (This message has not been sent yet. Try again in a few seconds), or the reply could not be added to a conversation

Simulate an Inbound Email ​

Test a mailbox without sending real mail. simulateInbound() delivers an email to one of your mailboxes, as if someone outside had written to it. The mailbox must belong to your account.

ts
const result = await outbound.sandbox.simulateInbound({
  to: 'claude-otp+gmail@inbound.example.com',
  from: 'noreply@accounts.example.org',
  subject: 'Your login code is 482913',
  text: 'Your login code is 482913.',
});

const { message } = await outbound.mailboxes.getMessage(result.messageId);

A simulated email goes through the same processing as a real one. The mailbox's allowedSenders, its enabled setting and the hourly limit all apply, and duplicate checks do too. If the mailbox accepts it, the message is stored, and the inbound webhook fires with details.simulated: true. The message has simulated: true too.

Parameters ​

FieldTypeRequiredDescription
tostringYesThe address of one of your mailboxes. A +tag is allowed
fromstringNoThe sender's address. Default sender@example.com. Use one plain email address
subjectstringNoDefault Simulated inbound email. Up to 500 characters
textstringNoPlain-text body. Default This is a simulated inbound email.. Up to 20,000 characters
htmlstringNoHTML body. Up to 200,000 characters

Response ​

Status 201.

ts
{
  simulated: true,
  mailboxId: '0199f2a4-6b1e-7c3d-8e2f-4a5b6c7d8e9f',
  messageId: '0199f2b7-1c3a-7e9d-b5f4-8a2c6d0e1f23'
}
FieldDescription
simulatedAlways true
mailboxIdThe mailbox that received the email. Pass it to Get Mailbox or List Messages
messageIdID of the stored message. Pass it to Get Message

Possible Errors ​

ErrorStatusCause
BadRequestError400to must be an email address when to cannot be read as an address. from must be one email address when from is not one address. <field> must be at most N characters when subject, text or html is too long. The length is checked before the value is trimmed. Also when a field does not exist, or subject, text or html is not a string
ForbiddenError403Inbound is not enabled for your account
NotFoundError404No mailbox of yours has the address <to>. to is not one of your mailboxes
OutboundError422The email was not delivered. The mailbox does not allow from, it is turned off, the hourly limit was reached, or the email is a duplicate of one already stored

Testing Common Cases ​

An out-of-office reply. It is classified as auto_reply and fires the auto_reply webhook:

ts
await outbound.sandbox.simulateReply({
  messageId,
  type: 'auto_reply',
  subject: 'Automatic reply: Your application',
  text: 'I am out of the office until Monday.',
});

A request to stop. The message comes back with optOut.detected: true, optOut.phrase: 'remove me' and optOut.action: 'flagged':

ts
await outbound.sandbox.simulateReply({
  messageId,
  text: 'Please remove me from this list.',
});

A reply with HTML, to check how your app renders getMessageHtml():

ts
await outbound.sandbox.simulateReply({
  messageId,
  text: 'Here are my documents.',
  html: '<p>Here are my <strong>documents</strong>.</p>',
});

Released under the MIT License.