// Configure default reply addressconst inbound = new Inbound({ apiKey: process.env.INBOUND_API_KEY!, defaultReplyFrom: 'support@yourdomain.com'})// Simple text replyawait inbound.reply(email, "Thanks for your message!")// Reply with optionsawait inbound.reply(email, { text: 'Thanks for your message!', html: '<p>Thanks for your message!</p>', attachments: [{ filename: 'invoice.pdf', content: base64Content }]})
async function sendWelcomeEmail(userEmail: string, userName: string) { const { id } = await inbound.emails.send({ from: 'welcome@yourdomain.com', to: userEmail, subject: 'Welcome to Our Service!', html: ` <h1>Welcome ${userName}!</h1> <p>We're excited to have you on board.</p> <a href="https://yourdomain.com/get-started">Get Started</a> `, text: `Welcome ${userName}! We're excited to have you on board.` }) return id}
// In your webhook handlerexport async function handleWebhook(payload: InboundWebhookPayload) { const { email } = payload // Check business hours const now = new Date() const hour = now.getHours() const isBusinessHours = hour >= 9 && hour < 17 if (!isBusinessHours) { // Send auto-reply await inbound.reply(email, { from: 'support@yourdomain.com', html: ` <p>Thank you for contacting us!</p> <p>We received your message outside of business hours. Our team will respond within 24 hours.</p> <p>Business hours: Mon-Fri 9AM-5PM EST</p> `, text: 'Thank you for contacting us! We received your message...' }) }}
The SDK is designed to be compatible with Resend’s API:
Copy
// Works like Resendconst { id } = await inbound.send({ from: 'you@yourdomain.com', to: 'them@example.com', subject: 'Hello', html: '<p>Hello World</p>'})// Get sent email detailsconst email = await inbound.emails.get(id)console.log('Email status:', email.last_event)