{"id":14978869,"url":"https://github.com/mailosaur/mailosaur-node","last_synced_at":"2026-02-17T13:04:08.720Z","repository":{"id":18901369,"uuid":"22119660","full_name":"mailosaur/mailosaur-node","owner":"mailosaur","description":"Mailosaur email and SMS testing library for Node.js","archived":false,"fork":false,"pushed_at":"2025-02-05T10:38:48.000Z","size":573,"stargazers_count":21,"open_issues_count":0,"forks_count":13,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T06:02:24.622Z","etag":null,"topics":["email","email-testing","end-to-end-testing","javascript","nodejs","playwright","qa","qaautomation","sms","testing-tools","webdriver","webdriverio"],"latest_commit_sha":null,"homepage":"https://mailosaur.com/docs/languages/nodejs/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mailosaur.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-07-22T20:33:01.000Z","updated_at":"2025-02-05T09:57:08.000Z","dependencies_parsed_at":"2024-06-18T15:35:14.578Z","dependency_job_id":"f9d609dc-a04f-46dd-ae94-84c98971205a","html_url":"https://github.com/mailosaur/mailosaur-node","commit_stats":{"total_commits":153,"total_committers":14,"mean_commits":"10.928571428571429","dds":0.2287581699346405,"last_synced_commit":"e2f14a3ebe57765511467d8097fc620eba6a9db4"},"previous_names":[],"tags_count":47,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailosaur%2Fmailosaur-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailosaur%2Fmailosaur-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailosaur%2Fmailosaur-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailosaur%2Fmailosaur-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mailosaur","download_url":"https://codeload.github.com/mailosaur/mailosaur-node/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247299829,"owners_count":20916190,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["email","email-testing","end-to-end-testing","javascript","nodejs","playwright","qa","qaautomation","sms","testing-tools","webdriver","webdriverio"],"created_at":"2024-09-24T13:58:33.474Z","updated_at":"2026-01-05T14:27:35.981Z","avatar_url":"https://github.com/mailosaur.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [Mailosaur - Node.js library](https://mailosaur.com/) \u0026middot; [![](https://github.com/mailosaur/mailosaur-node/workflows/CI/badge.svg)](https://github.com/mailosaur/mailosaur-node/actions) \n\nMailosaur lets you automate email and SMS tests as part of software development and QA.\n\n- **Unlimited test email addresses for all**  - every account gives users an unlimited number of test email addresses to test with.\n- **End-to-end (e2e) email and SMS testing** Allowing you to set up end-to-end tests for password reset emails, account verification processes and MFA/one-time passcodes sent via text message.\n- **Fake SMTP servers** Mailosaur also provides dummy SMTP servers to test with; allowing you to catch email in staging environments - preventing email being sent to customers by mistake.\n\n## Get Started\n\nThis guide provides several key sections:\n\n  - [Get Started](#get-started)\n  - [Creating an account](#creating-an-account)\n  - [Test email addresses with Mailosaur](#test-email-addresses-with-mailosaur)\n  - [Find an email](#find-an-email)\n  - [Find an SMS message](#find-an-sms-message)\n  - [Testing plain text content](#testing-plain-text-content)\n  - [Testing HTML content](#testing-html-content)\n  - [Working with hyperlinks](#working-with-hyperlinks)\n  - [Working with attachments](#working-with-attachments)\n  - [Working with images and web beacons](#working-with-images-and-web-beacons)\n  - [Spam checking](#spam-checking)\n\nYou can find the full [Mailosaur documentation](https://mailosaur.com/docs/) on the website.\n\nIf you get stuck, just contact us at support@mailosaur.com.\n\n### Installation\n\nInstall the Mailosaur Node.js library via npm or yarn:\n\n```sh\nnpm i -D mailosaur\n# or\nyarn add -D mailosaur\n```\n\nThen import the library into your code. The value for `YOUR_API_KEY` is covered in the next step ([creating an account](#creating-an-account)):\n\n```js\nconst MailosaurClient = require('mailosaur')\nconst mailosaur = new MailosaurClient('YOUR_API_KEY')\n```\n\n### API Reference\n\nThis library is powered by the Mailosaur [email \u0026 SMS testing API](https://mailosaur.com/docs/api/). You can easily check out the API itself by looking at our [API reference documentation](https://mailosaur.com/docs/api/) or via our Postman or Insomnia collections:\n\n[![Run in Postman](https://run.pstmn.io/button.svg)](https://app.getpostman.com/run-collection/6961255-6cc72dff-f576-451a-9023-b82dec84f95d?action=collection%2Ffork\u0026collection-url=entityId%3D6961255-6cc72dff-f576-451a-9023-b82dec84f95d%26entityType%3Dcollection%26workspaceId%3D386a4af1-4293-4197-8f40-0eb49f831325)\n [![Run in Insomnia}](https://insomnia.rest/images/run.svg)](https://insomnia.rest/run/?label=Mailosaur\u0026uri=https%3A%2F%2Fmailosaur.com%2Finsomnia.json)\n\n## Creating an account\n\nCreate a [free trial account](https://mailosaur.com/app/signup) for Mailosaur via the website.\n\nOnce you have this, navigate to the [API tab](https://mailosaur.com/app/project/api) to find the following values:\n\n- **Server ID** - Servers act like projects, which group your tests together. You need this ID whenever you interact with a server via the API.\n- **Server Domain** - Every server has its own domain name. You'll need this to send email to your server.\n- **API Key** - You can create an API key per server (recommended), or an account-level API key to use across your whole account. [Learn more about API keys](https://mailosaur.com/docs/managing-your-account/api-keys/).\n\n## Test email addresses with Mailosaur\n\nMailosaur gives you an **unlimited number of test email addresses** - with no setup or coding required!\n\nHere's how it works:\n\n* When you create an account, you are given a server.\n* Every server has its own **Server Domain** name (e.g. `abc123.mailosaur.net`)\n* Any email address that ends with `@{YOUR_SERVER_DOMAIN}` will work with Mailosaur without any special setup. For example:\n  * `build-423@abc123.mailosaur.net`\n  * `john.smith@abc123.mailosaur.net`\n  * `rAnDoM63423@abc123.mailosaur.net`\n* You can create more servers when you need them. Each one will have its own domain name.\n\n***Can't use test email addresses?** You can also [use SMTP to test email](https://mailosaur.com/docs/email-testing/sending-to-mailosaur/#sending-via-smtp). By connecting your product or website to Mailosaur via SMTP, Mailosaur will catch all email your application sends, regardless of the email address.*\n\n## Find an email\n\nIn automated tests you will want to wait for a new email to arrive. This library makes that easy with the `messages.get` method. Here's how you use it:\n\n```js\n(async () =\u003e {\n  const MailosaurClient = require('mailosaur')\n  const mailosaur = new MailosaurClient('API_KEY')\n\n  // See https://mailosaur.com/app/project/api\n  const serverId = 'abc123'\n  const serverDomain = 'abc123.mailosaur.net'\n\n  const searchCriteria = {\n    sentTo: 'anything@' + serverDomain\n  }\n  \n  const message = await mailosaur.messages.get(serverId, searchCriteria)\n\n  console.log(message.subject) // \"Hello world!\"\n})()\n```\n\n### What is this code doing?\n\n1. Sets up an instance of `MailosaurClient` with your API key.\n2. Waits for an email to arrive at the server with ID `abc123`.\n3. Outputs the subject line of the email.\n\n### My email wasn't found\n\nFirst, check that the email you sent is visible in the [Mailosaur Dashboard](https://mailosaur.com/api/project/messages). \n\nIf it is, the likely reason is that by default, `messages.get` only searches emails received by Mailosaur in the last 1 hour. You can override this behavior (see the `receivedAfter` option below), however we only recommend doing this during setup, as your tests will generally run faster with the default settings:\n\n```js\nconst email = await mailosaur.messages.get(\n  serverId,\n  searchCriteria,\n  // Override receivedAfter to search all messages since Jan 1st\n  { receivedAfter: new Date(2021, 01, 01) }\n)\n```\n\n## Find an SMS message\n\n**Important:** Trial accounts do not automatically have SMS access. Please contact our support team to enable a trial of SMS functionality.\n\nIf your account has [SMS testing](https://mailosaur.com/sms-testing/) enabled, you can reserve phone numbers to test with, then use the Mailosaur API in a very similar way to when testing email:\n\n```js\n(async () =\u003e {\n  const MailosaurClient = require('mailosaur')\n  const mailosaur = new MailosaurClient('API_KEY')\n\n  const serverId = 'abc123'\n\n  const searchCriteria = {\n    sentTo: '4471235554444'\n  }\n  \n  const sms = await mailosaur.messages.get(serverId, searchCriteria)\n\n  console.log(sms.text.body)\n})()\n```\n\n## Testing plain text content\n\nMost emails, and all SMS messages, should have a plain text body. Mailosaur exposes this content via the `text.body` property on an email or SMS message:\n\n```js\nconsole.log(message.text.body) // \"Hi Jason, ...\"\n\nif (message.text.body.indexOf('Jason') \u003e -1) {\n  console.log('Email contains \"Jason\"')\n}\n```\n\n### Extracting verification codes from plain text\n\nYou may have an email or SMS message that contains an account verification code, or some other one-time passcode. You can extract content like this using a simple regex.\n\nHere is how to extract a 6-digit numeric code:\n\n```js\nconsole.log(message.text.body) // \"Your access code is 243546.\"\n\nconst regEx = new RegExp('([0-9]{6})')\nconst matches = regEx.exec(message.text.body)\n\nconsole.log(matches[0]) // \"243546\"\n```\n\n[Read more](https://mailosaur.com/docs/test-cases/text-content/)\n\n## Testing HTML content\n\nMost emails also have an HTML body, as well as the plain text content. You can access HTML content in a very similar way to plain text:\n\n```js\nconsole.log(message.html.body) // \"\u003chtml\u003e\u003chead ...\"\n```\n\n### Working with HTML using JSDOM\n\nIf you need to traverse the HTML content of an email. For example, finding an element via a CSS selector, you can use the [JSDOM](https://github.com/jsdom/jsdom) library.\n\n```sh\nnpm i -D jsdom\n# or\nyarn add -D jsdom\n```\n\n```js\nconst { JSDOM } = require('jsdom')\n\n// ...\n\nconst dom = new JSDOM(message.html.body);\n\nconst el = dom.window.document.querySelector('.verification-code');\nconst verificationCode = el.textContent; // \"542163\"\n```\n\n[Read more](https://mailosaur.com/docs/test-cases/html-content/)\n\n## Working with hyperlinks\n\nWhen an email is sent with an HTML body, Mailosaur automatically extracts any hyperlinks found within anchor (`\u003ca\u003e`) and area (`\u003carea\u003e`) elements and makes these viable via the `html.links` array.\n\nEach link has a text property, representing the display text of the hyperlink within the body, and an href property containing the target URL:\n\n```js\n// How many links?\nconsole.log(message.html.links.length) // 2\n\nconst firstLink = message.html.links[0]\nconsole.log(firstLink.text) // \"Google Search\"\nconsole.log(firstLink.href) // \"https://www.google.com/\"\n```\n\n**Important:** To ensure you always have valid emails. Mailosaur only extracts links that have been correctly marked up with `\u003ca\u003e` or `\u003carea\u003e` tags.\n\n### Links in plain text (including SMS messages)\n\nMailosaur auto-detects links in plain text content too, which is especially useful for SMS testing:\n\n```js\n// How many links?\nconsole.log(message.text.links.length) // 2\n\nconst firstLink = message.text.links[0]\nconsole.log(firstLink.href) // \"https://www.google.com/\"\n```\n\n## Working with attachments\n\nIf your email includes attachments, you can access these via the `attachments` property:\n\n```js\n// How many attachments?\nconsole.log(message.attachments.length) // 2\n```\n\nEach attachment contains metadata on the file name and content type:\n\n```js\nconst firstAttachment = message.attachments[0]\nconsole.log(firstAttachment.fileName) // \"contract.pdf\"\nconsole.log(firstAttachment.contentType) // \"application/pdf\"\n```\n\nThe `length` property returns the size of the attached file (in bytes):\n\n```js\nconst firstAttachment = message.attachments[0]\nconsole.log(firstAttachment.length) // 4028\n```\n\n### Writing an attachment to disk\n\n```js\nconst fs = require('fs')\n\n// ...\n\nconst firstAttachment = message.attachments[1]\n\nconst fileBytes = await mailosaur.files.getAttachment(firstAttachment.id)\nfs.writeFileSync(firstAttachment.fileName, fileBytes)\n```\n\n## Working with images and web beacons\n\nThe `html.images` property of a message contains an array of images found within the HTML content of an email. The length of this array corresponds to the number of images found within an email:\n\n```js\n// How many images in the email?\nconsole.log(message.html.images.length) // 1\n```\n\n### Remotely-hosted images\n\nEmails will often contain many images that are hosted elsewhere, such as on your website or product. It is recommended to check that these images are accessible by your recipients.\n\nAll images should have an alternative text description, which can be checked using the `alt` attribute.\n\n```js\nconst image = message.html.images[0]\nconsole.log(image.alt) // \"Hot air balloon\"\n```\n\n### Triggering web beacons\n\nA web beacon is a small image that can be used to track whether an email has been opened by a recipient.\n\nBecause a web beacon is simply another form of remotely-hosted image, you can use the `src` attribute to perform an HTTP request to that address:\n\n```js\nconst https = require('https')\n\n// ...\n\nconst image = message.html.images[0]\nconsole.log(image.src) // \"https://example.com/s.png?abc123\"\n\n// Make an HTTP call to trigger the web beacon\nhttps.get(image.src, r =\u003e console.log(r.statusCode)) // 200\n```\n\n## Spam checking\n\nYou can perform a [SpamAssassin](https://spamassassin.apache.org/) check against an email. The structure returned matches the [spam test object](https://mailosaur.com/docs/api/#spam):\n\n```js\nconst result = await mailosaur.analysis.spam(message.id)\n\nconsole.log(result.score) // 0.5\n\nresult.spamFilterResults.spamAssassin.forEach(r =\u003e {\n  console.log(r.rule)\n  console.log(r.description)\n  console.log(r.score)\n})\n```\n\n## Development\n\nIf you'd like to contribute to this library, here is how to set it up locally.\n\nInstall all development dependencies:\n\n```sh\nnpm i\n```\n\nThe test suite requires the following environment variables to be set:\n\n```sh\nexport MAILOSAUR_API_KEY=your_api_key\nexport MAILOSAUR_SERVER=server_id\n```\n\nRun all tests:\n\n```sh\nnpm test\n```\n\n## Contacting us\n\nYou can get us at [support@mailosaur.com](mailto:support@mailosaur.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmailosaur%2Fmailosaur-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmailosaur%2Fmailosaur-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmailosaur%2Fmailosaur-node/lists"}