Legacy mail management API - Use email.received.* methods instead
Deprecated: The mail.* methods are deprecated. Use email.received.* methods instead.All mail.* methods will continue to work but show console warnings.Migration Guide: Replace inbound.mail.* with inbound.email.received.*
The unified email API provides a cleaner structure:
Copy
// ❌ OLD (Deprecated - but still works)const emails = await inbound.mail.list()const email = await inbound.mail.get('email_id')// ✅ NEW (Recommended)const emails = await inbound.email.received.list()const email = await inbound.email.received.get('email_id')// 🔄 OR use universal email.get() for any email typeconst email = await inbound.email.get('email_id') // Works for received OR sent emails
Reply to received emails directly through the mail API:
Copy
// Reply to an emailawait inbound.mail.reply({ emailId: 'email_abc123', to: 'customer@example.com', subject: 'Re: Your inquiry', textBody: 'Thank you for your message. We will get back to you soon.', htmlBody: '<p>Thank you for your message. We will get back to you soon.</p>'})
// Get all emails for a specific customerconst customerEmails = await inbound.mail.list({ emailAddress: 'customer@example.com', timeRange: '30d', includeArchived: true})console.log(`Found ${customerEmails.emails.length} emails for customer@example.com`)// Process customer support emailsconst supportEmails = await inbound.mail.list({ emailAddress: 'support@yourcompany.com', status: 'processed', limit: 100})// Auto-reply to support emailsfor (const email of supportEmails.emails) { if (!email.isRead) { await inbound.mail.reply({ emailId: email.id, to: email.from, subject: `Re: ${email.subject}`, textBody: 'Thank you for contacting support. We have received your message and will respond within 24 hours.' }) }}
// Get all emails in a specific thread using emailIdconst threadEmails = await inbound.mail.list({ emailId: 'original_email_123', includeArchived: true})console.log(`Thread contains ${threadEmails.emails.length} emails`)// Sort by date to see conversation flowconst sortedThread = threadEmails.emails.sort( (a, b) => new Date(a.receivedAt).getTime() - new Date(b.receivedAt).getTime())// Display conversation historysortedThread.forEach((email, index) => { console.log(`${index + 1}. ${email.subject} - ${email.from} (${email.receivedAt})`)})// Reply to the latest email in threadconst latestEmail = sortedThread[sortedThread.length - 1]await inbound.mail.reply({ emailId: latestEmail.id, to: latestEmail.from, subject: `Re: ${latestEmail.subject}`, textBody: 'Thank you for your follow-up message.'})
// Search for unprocessed ordersconst orderEmails = await inbound.mail.list({ search: 'order', timeRange: '24h', status: 'processed'})for (const email of orderEmails.emails) { // Get full email details const details = await inbound.mail.get(email.id) // Process order const orderNumber = extractOrderNumber(details.textBody) await processOrder(orderNumber) // Reply to confirm await inbound.mail.reply({ emailId: email.id, to: email.from, subject: `Order ${orderNumber} Confirmed`, textBody: `Your order ${orderNumber} has been received and is being processed.` })}
try { const emails = await inbound.mail.list()} catch (error) { if (error.message.includes('401')) { console.error('Invalid API key') } else if (error.message.includes('429')) { console.error('Rate limit exceeded') } else if (error.message.includes('Cannot filter by both emailAddress and emailId')) { console.error('Use either emailAddress OR emailId, not both') } else { console.error('API error:', error.message) }}
The emailAddress and emailId parameters cannot be used together in the same request. Use emailAddress to find all emails involving a specific address, or use emailId to find all emails in a specific thread.
Copy
// ✅ Correct - Filter by email addressconst addressEmails = await inbound.mail.list({ emailAddress: 'user@example.com'})// ✅ Correct - Filter by email IDconst threadEmails = await inbound.mail.list({ emailId: 'email_abc123'})// ❌ Incorrect - Both filters together will return an errortry { await inbound.mail.list({ emailAddress: 'user@example.com', emailId: 'email_abc123' // This will cause a 400 error })} catch (error) { console.error('Cannot use both emailAddress and emailId filters')}