GithubHelp home page GithubHelp logo

xielqs / mail.tm-api Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 2.0 35 KB

⚡A powerful library to use the Mail.TM and Mail.GW api to receive emails

Home Page: https://www.npmjs.com/package/mail.tm-api

License: MIT License

JavaScript 3.60% TypeScript 96.40%
mail mail-gw mail-tm nodejs temp-mail temp-mail-api mail-tm-api node-temp-mail xielq

mail.tm-api's Introduction

mail.tm-api

XielQ - mail.tm-api stars - mail.tm-api forks - mail.tm-api

GitHub release License issues - mail.tm-api

⚡ A powerful library to use the Mail.TM and Mail.GW api to receive email

Installation

$ npm install mail.tm-api
# Or
$ yarn add mail.tm-api
# Or
$ pnpm add mail.tm-api
# Or
$ bun add mail.tm-api

Getting Started

  • Note: All functions are async/await

Account

Create Account

There is a bunch of way to create an account

const MailTM = require('mail.tm-api');

const account = await MailTM.createAccount();
// Or you can specify the mail address & password
const account = await MailTM.createAccount('ADDRESS', 'PASSWORD');
// Example: MailTM.createAccount('George', 'mySuperDuperPass')

You can create account with only domain

const domain = await MailTM.fetchDomains({ getRandomDomain: true });

const account = await MailTM.createAccount(domain, 'PASSWORD');
// Without password
const account = await MailTM.createAccount(domain);

Login Account

const MailTM = require('mail.tm-api');

const account = await MailTM.loginAccount('ADDRESS@DOMAIN', 'PASSWORD');

// Login using JWT

const account = await MailTM.loginAccount('TOKEN');

Note: If you have a token, you can use it instead of the address & password

Fetch Account Info

console.log(await account.fetch());
// { id: 'ID', address: 'ADDRESS@DOMAIN', ... }

Delete Account

console.log(await account.delete());
// true

Domains

Fetch domains

const MailTM = require('mail.tm-api');

console.log(await MailTM.fetchDomains());
// [{ id: 'DOMAIN_ID', domain: 'DOMAIN' }]

// Fetch a specific page

console.log(await MailTM.fetchDomains({ page: 2 }));
// [{ id: 'DOMAIN_ID', domain: 'DOMAIN' }]

// Get random domain
console.log(await MailTM.fetchDomains({ getRandomDomain: true }));

Configure Class

const MailTM = require('mail.tm-api');

MailTM.setConfig({
 // Props Here
});

Available props

  • mailService [Optional & 'mail.tm' | 'mail.gw'] = 'mail.tm': Change mail service
  • axiosOptions [Optional & Object] = {}: Axios request options

Emails

Get a cached email

console.log(account.emails.cache.get('MAIL_ID'));
// { id: 'MAIL_ID', accountId: 'ACCOUNT_ID', ... }

Note: account.emails.cache is a Map object, you can use all Map methods

Fetch a email

console.log(await account.emails.fetch('MAIL_ID'));
// { id: 'MAIL_ID', accountId: 'ACCOUNT_ID', ... }

// Or

console.log(await account.emails.cache.get('MAIL_ID').fetch());
// { id: 'MAIL_ID', accountId: 'ACCOUNT_ID', ... }

Fetch all emails

console.log(await account.emails.fetchAll());
// [{ id: 'MAIL_ID', accountId: 'ACCOUNT_ID', ... }, ...]

// Fetch a specific page

console.log(await account.emails.fetchAll(2));
// [{ id: 'MAIL_ID', accountId: 'ACCOUNT_ID', ... }, ...]

Listen for new emails

account.on('newMail', email => {
 console.log(email);
 // { id: 'MAIL_ID', accountId: 'ACCOUNT_ID', ... }
});

Delete a email

console.log(await account.emails.cache.get('MAIL_ID').delete());
// { id: 'MAIL_ID', accountId: 'ACCOUNT_ID', ..., isDeleted: true }

// Or

console.log(await (await account.emails.fetch('MAIL_ID')).delete());
// { id: 'MAIL_ID', accountId: 'ACCOUNT_ID', ..., isDeleted: true }

Download a email

console.log(await account.emails.cache.get('MAIL_ID').download('PATH.eml'));
// PATH.eml

// Or

console.log(await (await account.emails.fetch('MAIL_ID')).download('PATH.eml'));
// PATH.eml

License

Released under MIT by @XielQs.

mail.tm-api's People

Contributors

xielqs avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

mail.tm-api's Issues

When removing account it prompts an error

Hello,
So i created a temporary e-mail generator using your library but when you remove an e-mail it prompts w/ an error and it crashes.
This is the error:
node:internal/process/promises:246
triggerUncaughtException(err, true /* fromPromise */);
^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "This account no longer exists.".] {
code: 'ERR_UNHANDLED_REJECTION'
}
Thanks,
Windows 20 @win20-official

Folder "Errors" should be "errors" in npm

Thanks for this nice package. But unfortunately i got on tiny error, because of the folder-name.

image

Can you please rename it in npm - like it's in the github-repo here?

Error is thrown because of:

image

image

Kindly regards 🙂

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.