Auto forwarding

MailSlurp inboxes support email auto-forwarding using inbox forwarders.

Code example

import {CreateInboxForwarderOptions, MailSlurp} from 'mailslurp-client';

const mailslurp = new MailSlurp({ apiKey: process.env.apiKey });
jest.setTimeout(timeout);

test('inbox forwarding', async () => {
    // create two inboxes for testing
    const inbox1 = await mailslurp.inboxController.createInboxWithDefaults()
    const inbox2 = await mailslurp.inboxController.createInboxWithDefaults()
    const inbox3 = await mailslurp.inboxController.createInboxWithDefaults()

    // add auto forwarding rule to inbox 2
    await mailslurp.inboxForwarderController.createNewInboxForwarder({
        field: CreateInboxForwarderOptions.FieldEnum.SENDER,
        match: inbox1.emailAddress,
        forwardToRecipients: [inbox3.emailAddress]
    }, inbox2.id)

    // send email from inbox1 to inbox2
    await mailslurp.sendEmail(inbox1.id!!, { to: [inbox2.emailAddress!!], subject:"Hello" })

    // see that inbox2 gets the original email
    const receivedEmail = await mailslurp.waitForLatestEmail(inbox2.id, 60000, true)
    expect(receivedEmail.subject).toContain("Hello")

    // see that inbox3 gets a forwarded email
    const forwardedEmail = await mailslurp.waitForLatestEmail(inbox3.id, 60000, true)
    expect(forwardedEmail.subject).toContain("Hello")
});