{"_id":"@bloodgang/mailjs","name":"@bloodgang/mailjs","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@bloodgang/mailjs","version":"1.0.0","description":"A JavaScript wrapper around the [mail.tm](https://docs.mail.tm/) api.","type":"module","source":"src/index.ts","main":"dist/mailjs.cjs","module":"dist/mailjs.mjs","browser":"dist/mailjs.min.js","types":"dist/index.d.ts","exports":{".":{"import":"./dist/mailjs.mjs","require":"./dist/mailjs.cjs","types":"./dist/index.d.ts"}},"scripts":{"build":"rollup --config","postbuild":"node tests.js"},"repository":{"type":"git","url":"git+https://github.com/bloodgang94/Mailjs.git"},"keywords":["mail","temp-mail"],"author":{"name":"Cemal"},"license":"MIT","bugs":{"url":"https://github.com/bloodgang94/Mailjs/issues"},"homepage":"https://github.com/bloodgang94/Mailjs#readme","dependencies":{"eventsource":"^2.0.2"},"devDependencies":{"@rollup/plugin-terser":"^0.4.4","@rollup/plugin-typescript":"^11.1.5","@types/eventsource":"^1.1.15","rollup":"^4.1.4","tslib":"^2.6.2","typescript":"^5.2.2"},"_id":"@bloodgang/mailjs@1.0.0","gitHead":"115989e9dad2f51138d2c83342d92bdbc38ea944","_nodeVersion":"20.13.1","_npmVersion":"10.5.1","dist":{"integrity":"sha512-Xd1Fswfuv6BV7M3sF2Z0rYZmsdymRIpCrENuiDsm8T9ieLNEdQ0mIf+ZOWizvLEUxIKVtCGc2Bj206HjG6Na7Q==","shasum":"ec301afb9272e0fb345904f015b8f006965ae79a","tarball":"https://registry.npmjs.org/@bloodgang/mailjs/-/mailjs-1.0.0.tgz","fileCount":8,"unpackedSize":32448,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC3Ouqmbd4DxhZOZB8o/rXa3X/EMKZNZYSezjDuZc7NrwIgJbj6MPkGFLZ7YZtlEggFdhAoHsLSKWGGRRzxrpW71fI="}]},"_npmUser":{"name":"rowi-test","email":"alexso94@yandex.ru"},"directories":{},"maintainers":[{"name":"rowi-test","email":"alexso94@yandex.ru"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mailjs_1.0.0_1717656053353_0.30126101451969545"},"_hasShrinkwrap":false}},"time":{"created":"2024-06-06T06:40:53.271Z","1.0.0":"2024-06-06T06:40:53.491Z","modified":"2024-06-06T06:40:53.753Z"},"maintainers":[{"name":"rowi-test","email":"alexso94@yandex.ru"}],"description":"A JavaScript wrapper around the [mail.tm](https://docs.mail.tm/) api.","homepage":"https://github.com/bloodgang94/Mailjs#readme","keywords":["mail","temp-mail"],"repository":{"type":"git","url":"git+https://github.com/bloodgang94/Mailjs.git"},"author":{"name":"Cemal"},"bugs":{"url":"https://github.com/bloodgang94/Mailjs/issues"},"license":"MIT","readme":"# Mailjs\r\n\r\nA JavaScript wrapper around the [mail.tm](https://docs.mail.tm/) api.\r\n\r\nProbably one of the best API for creating temporary email accounts.\r\n\r\n- Usage of our API for illegal activity is strictly prohibited.\r\n- It is forbidden to sell programs or earn from it that exclusively uses our API (for example, creating a competing temp mail client and charging for it's usage).\r\n- The general quota limit is 8 queries per second (QPS) per IP address.\r\n\r\n# Installation\r\n\r\n**npm**\r\n\r\n```sh\r\nnpm install @bloodgang/mailjs\r\n```\r\n\r\n**yarn**\r\n\r\n```sh\r\nyarn add @bloodgang/mailjs\r\n```\r\n\r\n**CDN**\r\n\r\n```\r\n<!-- It is only needed to listen to new messages. -->\r\n<script src=\"https://cdn.jsdelivr.net/gh/bloodgang/Mailjs@3.0.0/eventsource.min.js\"></script>\r\n<script src=\"https://cdn.jsdelivr.net/npm/@bloodgang/mailjs@3.0.0/dist/mailjs.min.js\"></script>\r\n```\r\n\r\n# Quickstart\r\n\r\n- Nodejs (CommonJS)\r\n\r\n```js\r\nconst Mailjs = require(\"@bloodgang/mailjs\");\r\n```\r\n\r\n- Nodejs (ESM)\r\n\r\n```js\r\nimport Mailjs from \"@bloodgang/mailjs\";\r\n```\r\n\r\n- Browser\r\n\r\n```html\r\n<!-- You can exlude this if not listening to events. -->\r\n<script src=\"https://cdn.jsdelivr.net/gh/bloodgang/Mailjs@1.0.0/eventsource.min.js\"></script>\r\n<!-- Mailjs library -->\r\n<script src=\"https://cdn.jsdelivr.net/npm/@bloodgang/mailjs@1.0.0/dist/mailjs.min.js\"></script>\r\n```\r\n\r\n[`EventSourcePolyfill`](https://github.com/EventSource/eventsource) is only for listening to new incoming messages, see [Events](#events) title for more information. Add [`EventSourcePolyfill`](https://github.com/EventSource/eventsource) before Mailjs.\r\n\r\n```js\r\nconst mailjs = new Mailjs();\r\n\r\nmailjs.createOneAccount().then((account) => console.log(account.data));\r\n```\r\n\r\nFor more reference visit [/examples](/examples) directory.\r\n\r\n# Documentation\r\n\r\nDefault domain domain mai.gw\r\nYou can override it\r\n\r\n```js\r\nconst mailjs = new Mailjs();\r\nmailjs.useDomain(\"mail.tm\");\r\n```\r\n\r\nReturns a Promise object after the function is called. If the request is sent correctly, `status` returns true. If it returns incorrect, the `status` will be false and the `message` in the data is also added. If there is no error, `status` always returns `true`.\r\n\r\nA successfull response example:\r\n\r\n```json\r\n{\r\n  \"status\": true,\r\n  \"message\": \"ok\",\r\n  \"data\": {}\r\n}\r\n```\r\n\r\nA failed response example:\r\n\r\n```json\r\n{\r\n  \"status\": false,\r\n  \"message\": \"Invalid credentials.\",\r\n  \"data\": {}\r\n}\r\n```\r\n\r\nExample use:\r\n\r\n```js\r\nconst acc = await mailjs.createOneAccount();\r\n\r\n// If there is a error.\r\nif (!acc.status) {\r\n  // Show the cause of the error.\r\n  console.error(acc.message);\r\n\r\n  return;\r\n}\r\n\r\n// If successful, access the data.\r\nconsole.log(acc.data);\r\n```\r\n\r\nTo see all results, check out the API page: [https://api.mail.tm/](https://api.mail.tm/).\r\n\r\nUser needs to login to access JWT token. Registration does not return this information, log in after registration.\r\n\r\nAfter the login process, the user's JWT token and ID are assigned to `mailjs.token` and `mailjs.id`\r\n\r\n---\r\n\r\n## Domain\r\n\r\n### List Domains\r\n\r\n```js\r\nmailjs.getDomains().then(console.log);\r\n```\r\n\r\n### Get Domain\r\n\r\n```js\r\nmailjs.getDomain(\"[domain id]\").then(console.log);\r\n```\r\n\r\n## Account\r\n\r\n### Create Account\r\n\r\n```js\r\nmailjs.register(\"user@example.com\", \"password\").then(console.log);\r\n```\r\n\r\n### Login\r\n\r\n`mailjs.token` and `mailjs.id` can be used to access the user token and id later.\r\n\r\n```js\r\nmailjs.login(\"user@example.com\", \"password\").then(console.log);\r\n```\r\n\r\n### Login With Token\r\n\r\nIf you use the JWT token stored in `mailjs.token` after login, it will allow you to login without username and password.\r\n\r\n```js\r\nmailjs.loginWithToken(\"eyJ0eXAiO...\").then(console.log);\r\n```\r\n\r\n### Get Account Data\r\n\r\n```js\r\nmailjs.me().then(console.log);\r\n```\r\n\r\n### Delete Account\r\n\r\n```js\r\nmailjs.deleteMe().then(console.log);\r\n```\r\n\r\nYou can also use the id to access the user's information and delete their account.\r\n\r\n```js\r\nmailjs.deleteAccount(\"[account id]\").then(console.log);\r\n```\r\n\r\n```js\r\nmailjs.getAccount(\"[account id]\").then(console.log);\r\n```\r\n\r\n## Message\r\n\r\n### List messages\r\n\r\nGets all the Message resources of a given page.\r\n\r\n```js\r\nmailjs.getMessages().then(console.log);\r\n```\r\n\r\n### Read a message\r\n\r\nRetrieves a Message resource with a specific id (It has way more information than a message retrieved with GET /messages but it hasn't the \"intro\" member)\r\n\r\n```js\r\nmailjs.getMessage(\"[message id]\").then(console.log);\r\n```\r\n\r\n### Delete a message\r\n\r\n```js\r\nmailjs.deleteMessage(\"[message id]\").then(console.log);\r\n```\r\n\r\n### Make a message readed or unreaded.\r\n\r\n`true` for make readed. `false` for make unreaded.\r\n\r\n```js\r\nmailjs.setMessageSeen(\"[message id]\", true).then(console.log);\r\n```\r\n\r\n## Events\r\n\r\nEvents are the **S**erver **S**ent **E**vents which are fired when message `arrive`, `seen` or `delete`. It also fires the `error`, `open` state.\r\n\r\n### on\r\n\r\nOpen an event listener to messages and error.\r\n\r\n```js\r\n// Add it before other activities if you need it.\r\nmailjs.on(\"open\", (msg) => console.log(\"Event listening has begun.\"));\r\n\r\n// When a new message arrives.\r\nmailjs.on(\"arrive\", (msg) =>\r\n  console.log(`Message id: ${msg.id} has arrived (${msg.intro}).`)\r\n);\r\n\r\n// When a message is marked as read.\r\nmailjs.on(\"seen\", (msg) =>\r\n  console.log(`Message id: ${msg.id} marked as seen.`)\r\n);\r\n\r\n// When a message is deleted.\r\nmailjs.on(\"delete\", (msg) =>\r\n  console.log(`Message id: ${msg.id} has been deleted.`)\r\n);\r\n\r\n// If an error occurs during listening.\r\nmailjs.on(\"error\", (err) => console.error(\"Something went wrong:\", err));\r\n```\r\n\r\n### off\r\n\r\nClears the events and safely closes event listener.\r\n\r\n```js\r\nmailjs.off();\r\n```\r\n\r\n## Source\r\n\r\n### Get source\r\n\r\nGets a Message's Source resource (If you don't know what this is, you either don't really want to use it or you should [read this!](https://en.wikipedia.org/wiki/Email#Plain_text_and_HTML))\r\n\r\n```js\r\nmailjs.getSource(\"[message id]\").then(console.log);\r\n```\r\n\r\n## Helper Methods\r\n\r\n### Create random account.\r\n\r\nCreates and logs in an account with a random username and password.\r\n\r\n```js\r\nmailjs.createOneAccount().then(console.log);\r\n```\r\n\r\n#### Response\r\n\r\n```json\r\n{\r\n  \"status\": true,\r\n  \"message\": \"ok\",\r\n  \"data\": {\r\n    \"username\": \"user@example.com\",\r\n    \"password\": \"my-password\"\r\n  }\r\n}\r\n```\r\n\r\n# Questions And Suggestions\r\n\r\nIf you have any questions or suggestions, please contact us via email [support@mail.tm](mailto:support@mail.tm) or [discord](https://discord.gg/Mhw2PDZBdk).\r\n","readmeFilename":"README.md"}