Code Monkey home page Code Monkey logo

mailslurp-client-ts-js's Introduction

Vue logo

Introduction

MailSlurp is a free API for sending and receiving emails from applications or tests. It is designed as a simpler, more powerful interface for SMTP mail servers.

This repository hosts the recommended MailSlurp client. MailSlurp can also be used as a REST API or with officially supported clients in Javascript, Ruby, Python, PHP, Java, C#, Go and more.

For more integrations see mailslurp.com

Documentation

Installing

npm install --save mailslurp-client

Configuration

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

๐Ÿ”‘ Note: All requests require an API Key. Get yours free via the MailSlurp Dashboard

Questions

Please reach out any time using live chat or email.

Issues

For anything related to this client please open an issue. For all other issues please contact support.

Examples

Creating email addresses

MailSlurp uses the concept of an inbox. Inboxes have IDs and email addresses. If you want to receive emails you'll need to create an inbox first.

const { id, emailAddress } = await mailslurp.createInbox()
// or if you prefer
const { id, emailAddress } = await mailslurp.createNewEmailAddress()

Sending emails

You can send real emails with MailSlurp. If you don't care what address it is sent from use the sendEmailSimple method. This will send emails from a random MailSlurp address.

mailslurp.sendEmailSimple({ to: ['[email protected]'], body: '', subject: '' })

If you want to send email from a specific address, first create an inbox. Then use that inbox's ID to send emails.

mailslurp.sendEmail(inbox.id, { to: ['[email protected]'], ...otherOptions })

For a full list of email sending options see the documentation. If you wish to send from custom domains see the pricing page.

To send attachments first upload each attachment you wish to send.

const [id] = await mailslurp.uploadAttachment({
    base64Contents: 'base64-encoded-file-contents',
    contentType: "optional/content-type",
    filename: "optional-filename"
})

Then use the returned attachment IDs in the attachments field of the send email options.

Receiving emails

MailSlurp is an asynchronous service. That means certain API calls will wait until a condition is met. This saves you from having to poll the API. (Webhooks are also available).

To receive an email first make sure you have an inbox with an email address. Then send an email to that address with any service (including MailSlurp itself). Now you can wait for the email to arrive.

let email = await mailslurp.waitForLatestEmail(inbox.id)
// other methods
email = await mailslurp.waitForNthEmail(inbox.id, index)
const emails = await mailslurp.waitForEmailCount(count, inbox.id)

โš ๏ธ Note: MailSlurp will return immediately if the inbox already contains an email.

For more control over email fetching use the getEmails methods. MailSlurp will hang the connection until all conditions are met or the timeout is exceeded.

// get a list of matching emails in preview form
const emailPreviews = await mailslurp.getEmails(inbox.id, {
    minCount: 2, // wait until 2 emails present
    retryTimeout: 60000 // max milliseconds to wait
})
// then get the email you want in full form
const email = await mailslurp.getEmail(emailPreviews[0].id)

Searching emails

MailSlurp has simple email matching features that let you wait for an email that matches a particular subject, recipient or more.

const matchOptions = {
  matches: [
    {
      field: 'SUBJECT',
      should: 'CONTAIN',
      value: 'Welcome to my company'
    }
  ]
};
await mailslurp.waitForMatchingEmails(matchOptions, 1, inbox.id, 5000);

For more information on email matching see the documentation.

Deleting entities

You can empty an inbox easily with:

await mailslurp.emptyInbox(inbox.id)

You can also delete emails individually:

await mailslurp.deleteEmail(email.id)

More information

See mailslurp.com for all information.

License

MIT License

mailslurp-client-ts-js's People

Contributors

jackmahoney avatar dependabot[bot] avatar klamping avatar cameroncf avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.