The reply functionality maintains email threading with proper In-Reply-To and References headers, ensuring replies appear in the correct conversation thread.
await inbound.reply(email, { from: '[email protected]', html: ` <div style="font-family: Arial, sans-serif;"> <p>Hi ${email.from?.addresses?.[0]?.name || 'there'},</p> <p>Thanks for contacting us! We've received your inquiry about:</p> <blockquote style="border-left: 3px solid #ccc; padding-left: 12px; color: #666;"> ${email.subject} </blockquote> <p>Our team will review and respond within 24 hours.</p> <p>Best regards,<br>Support Team</p> </div> `, text: `Hi ${email.from?.addresses?.[0]?.name || 'there'},Thanks for contacting us! We've received your inquiry about: ${email.subject}Our team will review and respond within 24 hours.Best regards,Support Team `.trim()})
await inbound.reply(email, { from: '[email protected]', subject: 'Re: Your Support Request #12345', text: 'We\'ve created ticket #12345 for your inquiry.'})
By default, replies go to the original sender. Override with:
await inbound.reply(email, { from: '[email protected]', to: '[email protected]', // Override recipient text: 'This reply goes to a different address.'})
export async function POST(request: NextRequest) { const payload = await request.json() const { email } = payload const subject = email.subject?.toLowerCase() || '' const body = email.text_body?.toLowerCase() || '' // Detect question type if (subject.includes('pricing') || body.includes('cost')) { await inbound.reply(email, { from: '[email protected]', html: ` <p>Thanks for your interest in our pricing!</p> <p>You can view our plans here: <a href="https://yourapp.com/pricing">Pricing Page</a></p> <p>For custom enterprise quotes, reply to this email or schedule a call.</p> ` }) } else if (subject.includes('support') || body.includes('help')) { await inbound.reply(email, { from: '[email protected]', html: ` <p>We've created a support ticket for your inquiry.</p> <p>Our team will respond within 24 hours.</p> ` }) } else { await inbound.reply(email, { from: '[email protected]', html: '<p>Thanks for your email! We\'ll get back to you soon.</p>' }) } return NextResponse.json({ success: true })}