Schedule email sending for recurring mail

How to send emails at a specific time or delay sending with email scheduling tools.

MailSlurp supports many sending and receiving methods for email. The job scheduler lets you send emails with a delay or specific send date.

Send delayed email

To compose an email and send it after a given number of seconds use the scheduled sending methods:

await mailslurp.inboxController.sendWithSchedule({
  inboxId: inbox.id,
  sendAtNowPlusSeconds: 1,
  validateBeforeEnqueue: true,
  sendEmailOptions: {
    to: [inbox.emailAddress],
    subject: 'test-schedule-123',
    body: '🌭',
  },
});

You can also pass an ISO date time to send at like so:

try {
  await mailslurp.inboxController.sendWithSchedule({
    // schedule sending 5 second from now
    sendAtTimestamp: new Date(new Date().getTime() + 5000),
    inboxId: inbox.id,
    validateBeforeEnqueue: true,
    sendEmailOptions: {
      to: [inbox.emailAddress],
      subject: 'test-schedule-at',
      body: '⏰',
    },
  });
} catch (e) {
  const errorMessage = await e.json()
  throw errorMessage
}
// now wait for the email to arrive
const expected = await mailslurp.waitController.waitForMatchingFirstEmail({
  inboxId: inbox.id,
  matchOptions: {
    matches: [
      {
        field: MatchOptionFieldEnum.SUBJECT,
        should: MatchOptionShouldEnum.CONTAIN,
        value: 'test-schedule-at',
      },
    ],
  },
  timeout: 60_000,
  unreadOnly: true,
});
expect(expected.body).toContain('⏰');

Listing scheduled emails

List the emails that are scheduled for sending with the inbox controller:

const inbox = await mailslurp.inboxController.createInboxWithDefaults();
const pageScheduledJobs =
  await mailslurp.inboxController.getScheduledJobsByInboxId({
    inboxId: inbox.id,
  });
expect(pageScheduledJobs.totalElements).toEqual(0);

Check schedule statuses

View the job schedule status using the inbox controller:

const pageScheduledJobs1 =
  await mailslurp.inboxController.getScheduledJobsByInboxId({
    inboxId: inbox.id,
  });
expect(pageScheduledJobs1.totalElements).toEqual(1);
expect(pageScheduledJobs1.content?.[0].status).toEqual('COMPLETED');

Ready to dive in?Start building email applications today.