You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
npm install freecustom-email
# or
pnpm add freecustom-email
# or
yarn add freecustom-email
Quick Start
import{FreecustomEmailClient}from'freecustom-email';constclient=newFreecustomEmailClient({apiKey: 'fce_your_api_key_here',});// Register an inboxawaitclient.inboxes.register('mytest@ditube.info');// Get latest OTPconstresult=awaitclient.otp.get('mytest@ditube.info');console.log(result.otp);// '482910'// Clean upawaitclient.inboxes.unregister('mytest@ditube.info');
API Reference
Client
constclient=newFreecustomEmailClient({apiKey: 'fce_...',// requiredbaseUrl: 'https://...',// optional, defaults to https://api2.freecustom.email/v1timeout: 10_000,// optional, ms, defaults to 10sretry: {// optionalattempts: 2,initialDelayMs: 500,},});
Inboxes
// Registerawaitclient.inboxes.register('mytest@ditube.info');// List all registered inboxesconstinboxes=awaitclient.inboxes.list();// [{ inbox: 'mytest@ditube.info', local: 'mytest', domain: 'ditube.info' }]// Unregisterawaitclient.inboxes.unregister('mytest@ditube.info');
Messages
// List all messagesconstmessages=awaitclient.messages.list('mytest@ditube.info');// Get a specific messageconstmsg=awaitclient.messages.get('mytest@ditube.info','D3vt8NnEQ');console.log(msg.subject,msg.otp,msg.verificationLink);// Delete a messageawaitclient.messages.delete('mytest@ditube.info','D3vt8NnEQ');// Wait for a message (polling helper)constmsg=awaitclient.messages.waitFor('mytest@ditube.info',{timeoutMs: 30_000,pollIntervalMs: 2_000,match: m=>m.from.includes('github.com'),});
OTP
// Get latest OTP (Growth plan+)constresult=awaitclient.otp.get('mytest@ditube.info');if(result.otp){console.log('OTP:',result.otp);console.log('Link:',result.verification_link);}// Wait for OTP — polls until it arrives (Growth plan+)constotp=awaitclient.otp.waitFor('mytest@ditube.info',{timeoutMs: 30_000,});console.log('Got OTP:',otp);
Full Verification Flow (convenience method)
// Register → trigger email → wait for OTP → unregister — all in one callconstotp=awaitclient.getOtpForInbox('mytest@ditube.info',async()=>{// This function should trigger your app to send the verification emailawaitfetch('https://yourapp.com/api/send-verification',{method: 'POST',body: JSON.stringify({email: 'mytest@ditube.info'}),});},{timeoutMs: 30_000,autoUnregister: true},);console.log('Verified with OTP:',otp);
// List available domains on your planconstdomains=awaitclient.domains.list();// With expiry metadataconstdomainsWithExpiry=awaitclient.domains.listWithExpiry();// Custom domains (Growth plan+)constcustom=awaitclient.domains.listCustom();constresult=awaitclient.domains.addCustom('mail.yourdomain.com');console.log('DNS records to add:',result.dns_records);constverification=awaitclient.domains.verifyCustom('mail.yourdomain.com');console.log('Verified:',verification.verified);awaitclient.domains.removeCustom('mail.yourdomain.com');
Webhooks
// Register a webhook (Startup plan+)consthook=awaitclient.webhooks.register('mytest@ditube.info','https://your-server.com/hooks/email',);console.log('Webhook ID:',hook.id);// List active webhooksconsthooks=awaitclient.webhooks.list();// Unregisterawaitclient.webhooks.unregister(hook.id);
import{FreecustomEmailClient,AuthError,PlanError,RateLimitError,NotFoundError,TimeoutError,FreecustomEmailError,}from'freecustom-email';try{constotp=awaitclient.otp.get('mytest@ditube.info');}catch(err){if(errinstanceofAuthError){console.error('Invalid API key');}elseif(errinstanceofPlanError){console.error('Plan too low:',err.message);console.error('Upgrade at:',err.upgradeUrl);}elseif(errinstanceofRateLimitError){console.error('Rate limited, retry after:',err.retryAfter,'seconds');}elseif(errinstanceofNotFoundError){console.error('Inbox not found or not registered');}elseif(errinstanceofTimeoutError){console.error('Request timed out');}elseif(errinstanceofFreecustomEmailError){console.error(`API error [${err.status}]: ${err.message}`);}}