npm

Need private packages and team management tools?Check out npm Orgs. »

mailslurp-client

3.0.25 • Public • Published

Official MailSlurp API Client

Create unlimited private test email accounts. Send and receive real emails with them. This library requires a MailSlurp account.

Links

Install

npm install -s mailslurp-client

Use

const MailSlurpClient = require('mailslurp-client')
const mailslurp = new MailSlurpClient({ apiKey: 'your-api-key' })

Common operations

// create a new email address and return { id: string, emailAdress: string }
createNewEmailAddress()Promise<Inbox>;
 
// send an email from a randomly generated email address
// to send from a know address see advanced operations
// sendEmailOptions must include recipients, subject and body
// for more options see SendEmailOptions definiton
// { to: string[], subject: string, body: string }
sendEmailSimple(sendEmailOptionsSendEmailOptions);
 
// get the latest email in an inbox or if empty wait for one to arrive
// must provide either inboxId or emailAddress of an inbox you have created
// for waiting on emails in non-empty inboxes see advanced operations
fetchLatestEmail(inboxEmailAddress?: string, inboxId?: string)Promise<Email>;

Examples

Here are some example use cases with an imaginary application that uses email addresses for user sign up and sends welcome emails.

Create new email and sign up user

const MailSlurpClient = require('mailslurp-client')
const mailslurp = new MailSlurpClient({ apiKey: 'your-api-key' })
 
let emailAddress;
 
test('can signup user', async () => {
    emailAddress = await mailslurp.createNewEmailAddress()
    const status = await myApplication.signUpUser(emailAddress)
    expect(status).to.equal(201)
})
 
test('user receives welcome email', async () => {
    const { subject, body } = await mailslurp.fetchLatestEmail(emailAddress)
    expect(subject).to.contain("Welcome to my app!")
    expect(body).to.contain("Thank you for joining")
    // can also use body to extract verification codes with regex capture
}) 

Send an email from unique address

const MailSlurpClient = require('mailslurp-client')
const mailslurp = new MailSlurpClient({ apiKey: 'your-api-key' })
 
test('can send email to my app', async () => {
    await mailslurp.sendEmailSimple({ 
        to: ['my-app@app.com'],
        subject: 'Hello support',
        body: '' 
    })
})
 
test('my app reacted to sent email', async () => {
    const handledEmail = await testAppReceivedEmail()
    expect(handledEmail).to.equal(true)
})

Extra operations

You can use MailSlurp in more advanced ways. Here are some method definitions. Read the source (it's small) for more information.

getEmail(emailIdstring)Promise<Email>;
 
getRawEmail(emailIdstring)Promise<string>;
 
createInbox()Promise<Inbox>;
 
bulkCreateInboxes(countnumber)Promise<Inbox[]>;
 
deleteInbox(inboxIdstring)Promise<Response>;
 
bulkDeleteInboxes(inboxIdsstring[])Promise<Response>;
 
getInbox(inboxIdstring)Promise<Inbox>;
 
getInboxes()Promise<Inbox[]>;
 
getEmails(inboxIdstring, argsGetMessagesOptions)Promise<EmailPreview[]>;
 
sendEmail(inboxIdstring, sendEmailOptionsSendEmailOptions)Promise<Response>
 
bulkSendEmails(bulkSendEmailOptionsBulkSendEmailOptions)Promise<Response>

Help and support

Please find extensive guides and documentation at developers portal. For help please see the support page.

install

npm i mailslurp-client

Downloadsweekly downloads

1,457

version

3.0.25

license

MIT

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability