commit bcfc9fb1531da543e40821e749bef12663d40703
parent 449fefc95d7bac8ee4967f188dfb4667082ef2e2
Author: Amit Dutta <mail@amit.is-a.dev>
Date: Thu, 3 Sep 2026 07:23:27 +0530
Merge pull request #7 from notamitgamer/fix/fetch-full-email-body
fix: fetch full email body from Resend (webhook only sends metadata)
Diffstat:
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/server.js b/server.js
@@ -88,13 +88,28 @@ app.post('/api/incoming', express.text({ type: 'application/json' }), async (req
return res.status(200).json({ success: true, message: 'Alias ignored' });
}
+ // The webhook payload only carries metadata (from/to/subject/email_id) —
+ // it does NOT include the actual html/text body. Fetch the full email
+ // via Resend's Retrieve Received Email endpoint using that ID.
+ let fullHtml = null;
+ let fullText = null;
+ if (emailData.email_id) {
+ const { data: fullEmail, error: getError } = await resend.emails.receiving.get(emailData.email_id);
+ if (getError) {
+ console.error('Failed to fetch full email body:', getError.message);
+ } else {
+ fullHtml = fullEmail?.html || null;
+ fullText = fullEmail?.text || null;
+ }
+ }
+
// --- 1. Store the full email as a real mailbox entry ---
const mailDoc = {
from: originalSender,
to: originalRecipient,
subject,
- html: emailData.html || null,
- text: emailData.text || null,
+ html: fullHtml,
+ text: fullText,
resendEmailId: emailData.email_id || null,
read: false,
receivedAt: admin.firestore.FieldValue.serverTimestamp(),