mail.tm-api
⚡ A powerful library to use the Mail.TM and Mail.GW api to receive email
Installation
$ npm install mail.tm-api
$ yarn add mail.tm-api
$ pnpm add mail.tm-api
$ 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();
const account = await MailTM.createAccount('ADDRESS', 'PASSWORD');
You can create account with only domain
const domain = await MailTM.fetchDomains({ getRandomDomain: true });
const account = await MailTM.createAccount(domain, 'PASSWORD');
const account = await MailTM.createAccount(domain);
Login Account
const MailTM = require('mail.tm-api');
const account = await MailTM.loginAccount('ADDRESS@DOMAIN', 'PASSWORD');
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());
Delete Account
console.log(await account.delete());
Domains
Fetch domains
const MailTM = require('mail.tm-api');
console.log(await MailTM.fetchDomains());
console.log(await MailTM.fetchDomains({ page: 2 }));
console.log(await MailTM.fetchDomains({ getRandomDomain: true }));
Configure Class
const MailTM = require('mail.tm-api');
MailTM.setConfig({
});
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'));
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'));
console.log(await account.emails.cache.get('MAIL_ID').fetch());
Fetch all emails
console.log(await account.emails.fetchAll());
console.log(await account.emails.fetchAll(2));
Listen for new emails
account.on('newMail', email => {
console.log(email);
});
Delete a email
console.log(await account.emails.cache.get('MAIL_ID').delete());
console.log(await (await account.emails.fetch('MAIL_ID')).delete());
Download a email
console.log(await account.emails.cache.get('MAIL_ID').download('PATH.eml'));
console.log(await (await account.emails.fetch('MAIL_ID')).download('PATH.eml'));
License
Released under MIT by @XielQs.