{"id":18721050,"url":"https://github.com/limedeck/nodemailer-stub","last_synced_at":"2025-04-12T14:30:21.315Z","repository":{"id":48002190,"uuid":"81820636","full_name":"LimeDeck/nodemailer-stub","owner":"LimeDeck","description":"✉️️ Stub transport for Nodemailer. Testing your mails in Node.js is now easy.","archived":false,"fork":false,"pushed_at":"2022-12-06T17:30:06.000Z","size":467,"stargazers_count":10,"open_issues_count":9,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-09T03:25:42.656Z","etag":null,"topics":["nodejs","nodemailer","nodemailer-transport","testing"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LimeDeck.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}},"created_at":"2017-02-13T12:01:39.000Z","updated_at":"2022-10-28T14:43:07.000Z","dependencies_parsed_at":"2023-01-24T10:32:13.842Z","dependency_job_id":null,"html_url":"https://github.com/LimeDeck/nodemailer-stub","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LimeDeck%2Fnodemailer-stub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LimeDeck%2Fnodemailer-stub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LimeDeck%2Fnodemailer-stub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LimeDeck%2Fnodemailer-stub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LimeDeck","download_url":"https://codeload.github.com/LimeDeck/nodemailer-stub/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248580928,"owners_count":21128080,"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":["nodejs","nodemailer","nodemailer-transport","testing"],"created_at":"2024-11-07T13:33:24.297Z","updated_at":"2025-04-12T14:30:21.292Z","avatar_url":"https://github.com/LimeDeck.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nodemailer-stub\n\n[![Build Status](https://travis-ci.org/LimeDeck/nodemailer-stub.svg?branch=master)](https://travis-ci.org/LimeDeck/nodemailer-stub)\n[![Coverage Status](https://coveralls.io/repos/github/LimeDeck/nodemailer-stub/badge.svg?branch=master)](https://coveralls.io/github/LimeDeck/nodemailer-stub?branch=master)\n[![npm](https://img.shields.io/npm/dt/nodemailer-stub.svg)](https://www.npmjs.com/package/nodemailer-stub)\n[![GitHub release](https://img.shields.io/github/release/limedeck/nodemailer-stub.svg)]()\n\nNodemailer-stub comes with a stub transport for [Nodemailer](https://github.com/nodemailer/nodemailer). The Stub stores the messages in memory but mimics real mail behaviour. It also contains a smart testing class called InteractsWithMail, which allows users to access, read, count and flush the messages in memory in their testing environment.\n\n## Installation\n```console\n$ yarn add nodemailer-stub -D\n#... or via npm\n$ npm install nodemailer-stub --save-dev\n```\n\n## Usage\nThis is an example use case for the Stub.\n\n```javascript\nimport { stubTransport } from 'nodemailer-stub'\nimport nodeMailer from 'nodemailer'\n\nlet transport = nodeMailer.createTransport(stubTransport)\n\nlet mail = await transport.sendMail({\n  from: 'john.doe@domain.com',\n  to: 'jim@otherdomain.com',\n  subject: 'Nodemailer stub works!',\n  text: 'Wohoo'\n})\n```\n\nFor testing purposes, there is also a transport called `errorTransport`, where\nthe transport throws an error during execution, to help with testing the\nrobustness of your mail service logic.\n\nWe've also included a testing utility class, called `interactsWithMail`. You can use it in your tests like this:\n\n```javascript\nimport { interactsWithMail as iwm } from 'nodemailer-stub'\n\nconst exampleMail = {\n  to: 'john@domain.com',\n  from: 'jimmy@domain.com',\n  subject: 'testing',\n  content: 'foo',\n  contents: ['foo'],\n  contentType: 'text/plain'\n}\n\ntest('it retrieves the last message', () =\u003e {\n  iwm.newMail(exampleMail)\n\n  let lastMail = iwm.lastMail()\n\n  lastMail.to.should.eq('john@domain.com')\n  lastMail.from.should.eq('jimmy@domain.com')\n  lastMail.subject.should.eq('testing')\n  lastMail.content.should.eq(['foo'])\n  lastMail.contents.should.eq(['foo'])\n  lastMail.contentType.should.eq('text/plain')\n})\n```\n\n**Available methods for `interactsWithMail`**:\n### `lastMail()`\nRetrieves last mail.\nAccessible properties:\n\n- from\n- to\n- subject\n- content\n- contents\n- contentType\n\n### `newMail (Object)`\nAdds a new mail to the list of all mails.\n\nAvailable properties:\n\n- from (required)\n- to (required)\n- subject\n- text (required)\n\n### `flushMails ()`\nFlushes all messages. Useful when testing multiple occurrences of mailer, and should be used in afterAll or afterEach hooks in your tests.\n\n### `sentMailsCount ()`\nRetrieves a count of how many emails were sent in the last mailer call.\n\n## Testing\nAll tests can be executed with the following command:\n\n```console\n$ yarn test\n```\n\n## License\nSee LICENSE file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flimedeck%2Fnodemailer-stub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flimedeck%2Fnodemailer-stub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flimedeck%2Fnodemailer-stub/lists"}