MailSlurp JS

Globals / MailSlurp

# Class: MailSlurp

Create an instance of this class to call MailSlurp API methods.

Contains top level convenience functions. Access the full API controllers as properties on the instance.

# Create instance

You must provide a configuration object with your API Key (opens new window) as the apiKey property when creating a new instance.

const MailSlurp = require('mailslurp-client').default;
const mailslurp = new MailSlurp({
 apiKey: 'xxxx'
})

# Call methods

Most methods are asynchronous and return Promises. You can await the results or use .then(result => {})

// call convenience functions
const email = await mailslurp.waitForLatestEmail(...args)
// call controllers to access full API methods
const alias = await mailslurp.aliasController.createAlias(...args)
// or create a controller
const inboxController = mailslurp.inboxController
const inbox = await inboxController.createInbox()
// use Promises methods if you prefer
mailslurp.getEmails(inbox.id).then(emails => {
   // handle emails
   console.log(emails))
 }

# Hierarchy

  • MailSlurp

# Index

# Constructors

# Properties

# Methods

# Constructors

# constructor

+ new MailSlurp(opts: Config): MailSlurp

Defined in src/index.ts:101 (opens new window)

Create a new MailSlurp instance.

Contains top level convenience functions. Access the full API controllers as properties on the instance.

const MailSlurp = require('mailslurp-client').default
const mailslurp = new MailSlurp({ apiKey })

# Parameters:

Name Type Description
opts Config

Returns: MailSlurp

# Properties

# aliasController

Readonly aliasController: AliasControllerApi

Defined in src/index.ts:95 (opens new window)


# attachmentController

Readonly attachmentController: AttachmentControllerApi

Defined in src/index.ts:89 (opens new window)


# bulkController

Readonly bulkController: BulkActionsControllerApi

Defined in src/index.ts:92 (opens new window)


# commonController

Readonly commonController: CommonActionsControllerApi

Defined in src/index.ts:91 (opens new window)


# contactController

Readonly contactController: ContactControllerApi

Defined in src/index.ts:98 (opens new window)


# domainController

Readonly domainController: DomainControllerApi

Defined in src/index.ts:97 (opens new window)


# emailController

Readonly emailController: EmailControllerApi

Defined in src/index.ts:87 (opens new window)


# formController

Readonly formController: FormControllerApi

Defined in src/index.ts:96 (opens new window)


# groupController

Readonly groupController: GroupControllerApi

Defined in src/index.ts:99 (opens new window)


# inboxController

Readonly inboxController: InboxControllerApi

Defined in src/index.ts:88 (opens new window)


# templateController

Readonly templateController: TemplateControllerApi

Defined in src/index.ts:100 (opens new window)


# waitController

Readonly waitController: WaitForControllerApi

Defined in src/index.ts:93 (opens new window)


# webhookController

Readonly webhookController: WebhookControllerApi

Defined in src/index.ts:101 (opens new window)

# Methods

# createInbox

createInbox(emailAddress?: string, name?: string, description?: string, expiresAt?: Date, favourite?: boolean, tags?: Array&lt;string>): Promise<Inbox>

Defined in src/index.ts:159 (opens new window)

Create a new inbox and with a randomized email address to send and receive from. Pass emailAddress parameter if you wish to use a specific email address. Creating an inbox is required before sending or receiving emails. If writing tests it is recommended that you create a new inbox during each test method so that it is unique and empty.

summary Create an Inbox (email address)

# Parameters:

Name Type
emailAddress? string
name? string
description? string
expiresAt? Date
favourite? boolean
tags? Array&lt;string>

Returns: Promise<Inbox>


# deleteEmail

deleteEmail(emailId: string): Promise<Response>

Defined in src/index.ts:345 (opens new window)

Deletes an email and removes it from the inbox. Deleted emails cannot be recovered.

summary Delete an email

# Parameters:

Name Type Description
emailId string emailId

Returns: Promise<Response>


# deleteInbox

deleteInbox(inboxId: string): Promise<Response>

Defined in src/index.ts:184 (opens new window)

Permanently delete an inbox and associated email address aswell as all emails within the given inbox. This action cannot be undone. Note: deleting an inbox will not affect your account usage. Monthly inbox usage is based on how many inboxes you create within 30 days, not how many exist at time of request.

summary Delete inbox

# Parameters:

Name Type Description
inboxId string inboxId

Returns: Promise<Response>


# downloadAttachment

downloadAttachment(emailId: string, attachmentId: string): Promise&lt;String>

Defined in src/index.ts:443 (opens new window)

Returns the specified attachment for a given email as a byte stream (file download). You can find attachment ids in email responses endpoint responses. The response type is application/octet-stream.

summary Get email attachment bytes

# Parameters:

Name Type Description
emailId string emailId
attachmentId string attachmentId

Returns: Promise&lt;String>


# emptyInbox

emptyInbox(inboxId: string): Promise<Response>

Defined in src/index.ts:195 (opens new window)

Deletes all emails

summary Delete all emails in an inbox

# Parameters:

Name Type Description
inboxId string inboxId

Returns: Promise<Response>


# getAllEmails

getAllEmails(page?: number, size?: number, inboxId?: Array&lt;string>, sort?: SortEnum, unreadOnly?: boolean): Promise<PageEmailProjection>

Defined in src/index.ts:360 (opens new window)

By default returns all emails across all inboxes sorted by ascending created at date. Responses are paginated. You can restrict results to a list of inbox IDs. You can also filter out read messages

summary Get all emails

# Parameters:

Name Type
page? number
size? number
inboxId? Array&lt;string>
sort? SortEnum
unreadOnly? boolean

Returns: Promise<PageEmailProjection>


# getAllInboxes

getAllInboxes(page?: number, size?: number, favourite?: boolean, search?: string, sort?: SortEnum, tag?: string): Promise<PageInboxProjection>

Defined in src/index.ts:230 (opens new window)

List inboxes in paginated form. Allows for page index, page size, and sort direction. Can also filter by favourited or email address like pattern.

summary List Inboxes Paginated

# Parameters:

Name Type
page? number
size? number
favourite? boolean
search? string
sort? SortEnum
tag? string

Returns: Promise<PageInboxProjection>


# getAttachmentMetaData

getAttachmentMetaData(attachmentId: string, emailId: string): Promise<AttachmentMetaData>

Defined in src/index.ts:476 (opens new window)

Get attachment MetaData

MetaData includes name, size (bytes) and content-type.

summary Get email attachment metadata

# Parameters:

Name Type Description
attachmentId string attachmentId
emailId string emailId

Returns: Promise<AttachmentMetaData>


# getEmail

getEmail(emailId: string): Promise<Email>

Defined in src/index.ts:405 (opens new window)

Returns an EmailDto object with headers and content. To retrieve the raw unparsed email use the getRawEmail endpoints

summary Get email content

# Parameters:

Name Type Description
emailId string emailId

Returns: Promise<Email>


# getEmails

getEmails(inboxId: string, args?: GetMessagesOptions): Promise<EmailPreview[]>

Defined in src/index.ts:384 (opens new window)

List emails that an inbox has received. Only emails that are sent to the inbox's email address will appear in the inbox. It may take several seconds for any email you send to an inbox's email address to appear in the inbox. To make this endpoint wait for a minimum number of emails use the minCount parameter. The server will retry the inbox database until the minCount is satisfied or the retryTimeout is reached

summary Get emails in an Inbox

# Parameters:

Name Type Default value Description
inboxId string - Id of inbox that emails belongs to
args GetMessagesOptions {} -

Returns: Promise<EmailPreview[]>


# getInbox

getInbox(inboxId: string): Promise<Inbox>

Defined in src/index.ts:206 (opens new window)

Returns an inbox's properties, including its email address and ID.

summary Get Inbox

# Parameters:

Name Type Description
inboxId string inboxId

Returns: Promise<Inbox>


# getInboxes

getInboxes(): Promise<Inbox[]>

Defined in src/index.ts:216 (opens new window)

List the inboxes you have created

summary List Inboxes / Email Addresses

Returns: Promise<Inbox[]>


# getRawEmail

getRawEmail(emailId: string): Promise&lt;string>

Defined in src/index.ts:416 (opens new window)

Returns a raw, unparsed, and unprocessed email. If your client has issues processing the response it is likely due to the response content-type which is text/plain. If you need a JSON response content-type use the getRawEmailJson endpoint

summary Get raw email string

# Parameters:

Name Type Description
emailId string emailId

Returns: Promise&lt;string>


# sendEmail

sendEmail(inboxId: string, sendEmailOptions: SendEmailOptions): Promise<Response>

Defined in src/index.ts:428 (opens new window)

Send an email from an inbox's email address. The request body should contain the SendEmailOptions that include recipients, attachments, body etc. See SendEmailOptions for all available properties. Note the inboxId refers to the inbox's id not the inbox's email address. See https://www.mailslurp.com/guides/ for more information on how to send emails.

summary Send Email

# Parameters:

Name Type Description
inboxId string ID of the inbox you want to send the email from
sendEmailOptions SendEmailOptions -

Returns: Promise<Response>


# uploadAttachment

uploadAttachment(options: UploadAttachmentOptions): Promise<Array&lt;String>>

Defined in src/index.ts:460 (opens new window)

Upload an attachment for use in email sending. Attachment contents must be a base64 encoded string. When sending emails with attachments first upload each attachment with this endpoint. Record the returned attachment IDs. Then use these attachment IDs in the SendEmailOptions when sending an email. This means that attachments can easily be reused.

summary Upload an attachment for sending

# Parameters:

Name Type
options UploadAttachmentOptions

Returns: Promise<Array&lt;String>>


# waitForEmailCount

waitForEmailCount(count?: number, inboxId?: string, timeout?: number, unreadOnly?: boolean): Promise<EmailPreview[]>

Defined in src/index.ts:324 (opens new window)

If inbox contains count or more emails at time of request then return count worth of emails. If not wait until the count is reached and return those or return an error if timeout is exceeded.

summary Wait for and return count number of emails

# Parameters:

Name Type
count? number
inboxId? string
timeout? number
unreadOnly? boolean

Returns: Promise<EmailPreview[]>


# waitForLatestEmail

waitForLatestEmail(inboxId?: string, timeout?: number, unreadOnly?: boolean): Promise<Email>

Defined in src/index.ts:258 (opens new window)

Will return either the last received email or wait for an email to arrive and return that. If you need to wait for an email for a non-empty inbox see the other receive methods such as waitForNthEmail or waitForEmailCount.

summary Fetch inbox's latest email or if empty wait for an email to arrive

# Parameters:

Name Type
inboxId? string
timeout? number
unreadOnly? boolean

Returns: Promise<Email>


# waitForMatchingEmails

waitForMatchingEmails(matchOptions: MatchOptions, count?: number, inboxId?: string, timeout?: number, unreadOnly?: boolean): Promise<EmailPreview[]>

Defined in src/index.ts:299 (opens new window)

Perform a search of emails in an inbox with the given patterns. If results match expected count then return or else retry the search until results are found or timeout is reached. Match options allow simple CONTAINS or EQUALS filtering on SUBJECT, TO, BCC, CC, and FROM. See the MatchOptions object for options.

summary Wait or return list of emails that match simple matching patterns

# Parameters:

Name Type Description
matchOptions MatchOptions matchOptions
count? number -
inboxId? string -
timeout? number -
unreadOnly? boolean -

Returns: Promise<EmailPreview[]>


# waitForNthEmail

waitForNthEmail(inboxId: string, index: number, timeout?: number, unreadOnly?: boolean): Promise<Email>

Defined in src/index.ts:275 (opens new window)

If nth email is already present in inbox then return it. If not hold the connection open until timeout expires or the nth email is received and returned.

summary Wait for or fetch the email with a given index in the inbox specified

# Parameters:

Name Type
inboxId string
index number
timeout? number
unreadOnly? boolean

Returns: Promise<Email>