Giter VIP home page Giter VIP logo

mailjs's Introduction

Mailjs

A JavaScript wrapper around the mail.tm api.

Probably one of the best API for creating temporary email accounts.

  • Usage of our API for illegal activity is strictly prohibited.
  • 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).
  • The general quota limit is 8 queries per second (QPS) per IP address.

Installation

npm

npm install @cemalgnlts/mailjs

yarn

yarn add @cemalgnlts/mailjs

CDN

<script src="https://cdn.jsdelivr.net/gh/cemalgnlts/Mailjs@latest/mailjs.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/cemalgnlts/[email protected]/eventsource.min.js"></script>

Quickstart

  • Nodejs (CommonJS)
const Mailjs = require("@cemalgnlts/mailjs");
const mailjs = new Mailjs();
mailjs.createOneAccount()
	.then(account => {
		console.log(account.data);
	});

mailjs.on("ready" , () => console.log("Ready To Listen!"));
mailjs.on("arrive" , msg => console.log(msg));
  • Nodejs (ESM)
import Mailjs from "@cemalgnlts/mailjs";
const mailjs = new Mailjs();
  • Browser

Include these scripts in html page before using to include the extented polyfill of eventsouce and mailjs.

<script src="https://cdn.jsdelivr.net/gh/cemalgnlts/Mailjs@latest/mailjs.min.js"></script>

<!-- you can exlude this if not listening to events (may cause runtime error) -->
<script src="https://cdn.jsdelivr.net/gh/cemalgnlts/Mailjs@latest/eventsource.min.js"></script>

<script>
	const mailjs = new Mailjs();
</script>

For more reference visit /examples directory.

Documentation

Returns 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.

A successfull response example:

{
  "status": true,
  "message": "ok",
  "data": {}
}

A failed response example:

{
  "status": false,
  "message": "Invalid credentials.",
  "data": {}
}

To see all results, check out the API page: https://api.mail.tm/

User needs to login to access JWT token. Registration does not return this information, log in after registration.

After the login process, the user's JWT token and ID are assigned to mailjs.token and mailjs.id


Domain

List Domains

mailjs.getDomains()
  .then(console.log)

Get Domain

mailjs.getDomain("[domain id]")
  .then(console.log)

Account

Create Account

mailjs.register("[email protected]", "password")
  .then(console.log)

Login

mailjs.token and mailjs.id can be used to access the user token and id later.

mailjs.login("[email protected]", "password")
  .then(console.log)

Login With Token

If you use the JWT token stored in mailjs.token after login, it will allow you to login without username and password.

mailjs.loginWithToken("eyJ0eXAiO...")
  .then(console.log)

Get Account Data

mailjs.me()
  .then(console.log)

Delete Account

mailjs.deleteMe()
  .then(console.log)

You can also use the id to access the user's information and delete their account.

mailjs.deleteAccount("[account id]")
  .then(console.log)
mailjs.getAccount("[account id]")
  .then(console.log)

Message

List messages

Gets all the Message resources of a given page.

mailjs.getMessages()
  .then(console.log)

Read a message

Retrieves 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)

mailjs.getMessage("[message id]")
  .then(console.log)

Delete a message

mailjs.deleteMessage("[message id]")
  .then(console.log)

Make a message readed or unreaded.

true for make readed. false for make unreaded.

mailjs.setMessageSeen("[message id]", true)
  .then(console.log)

Events

Events are the Server Sent Events which are fired when message arrive,seen or delete. It also fires the error and ready state.

Example

mailjs.on("ready" , ()=>console.log("Ready to listen to Messages"));
mailjs.on("seen" , (msg)=>console.log(`Message id:${msg.id} marked as seen.`));
mailjs.on("delete" , (msg)=>console.log(`Message id:${msg.id} has been deleted.`));
mailjs.on("arrive" , (msg)=>console.log(`Message id:${msg.id} has arrived. Preview ${msg.intro}`));
mailjs.on("error" , (err)=>console.log(`Something went wrong. ${err}`));

Source

Get source

Gets 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!)

mailjs.getSource("[message id]")
  .then(console.log)

Helper Methods

Create random account.

Creates and logs in an account with a random username and password.

mailjs.createOneAccount()
  .then(console.log);

Response

{
  "status": true,
  "data": {
    "username": "[email protected]",
    "password": "my-password"
  }
}

Questions And Suggestions

If you have any questions or suggestions, please contact us via email [email protected] or discord.

mailjs's People

Contributors

asyncfox avatar cemalgnlts avatar shivam1608 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.