Saltar al contenido principal

πŸ” Why Your Attachment Was Empty

Date: November 5, 2025
Issue: Email sent, but PDF attachment was empty
Root Cause: Missing base64 content in the request


πŸ“§ WHAT YOU SAW​

Your .eml file showed:

--boundary
Content-Disposition: attachment; filename="attachment"
Content-Transfer-Encoding: base64
Content-Type: application/octet-stream; name="attachment"

← NOTHING HERE! Empty!
--boundary--

The attachment structure was there, but the PDF data was missing!


❌ WHAT WENT WRONG​

Your Request Probably Looked Like This:​

{
"businessId": "...",
"recipientContact": "luisrangelc@gmail.com",
"channel": "email",
"type": "invoice",
"subject": "Your Invoice #430",
"content": "Plain text or HTML",
"attachments": [
{
"filename": "invoice.pdf",
"fileUrl": "https://..." // ❌ fileUrl doesn't work!
}
]
}

OR:

{
"attachments": [
{
"filename": "invoice.pdf",
"content": "", // ❌ Empty!
"mimeType": "application/pdf"
}
]
}

OR:

{
"attachments": [
{
"filename": "invoice.pdf",
"mimeType": "application/pdf"
// ❌ Missing content entirely!
}
]
}

βœ… WHAT IT SHOULD LOOK LIKE​

Correct Request:​

{
"businessId": "33b6db4b-51c5-45ee-8d04-c01c2d157f66",
"createdBy": "6c0c4f32-d74a-4a84-892f-3bead447d765",
"recipientContact": "luisrangelc@gmail.com",
"channel": "email",
"type": "invoice",
"subject": "Your Invoice #430",
"content": "<p>Invoice attached</p>",
"attachments": [
{
"filename": "invoice.pdf",
"content": "JVBERi0xLjQKJeLjz9MyCjYgMCBvYmoKPDwvTGluZWFyaXplZCAxL0wgMzQ2NzQvTyA4L0UgMjEzNjQvTiAxL1QgMzQzODUvSCBbIDUxNiAxNTRdPj4...",
"mimeType": "application/pdf"
}
]
}

See the content field? That's the base64-encoded PDF! It MUST be there!


🎯 THE CORRECT WORKFLOW​

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ STEP 1: Generate PDF β”‚
β”‚ POST /communications/generate-pdf β”‚
β”‚ β”‚
β”‚ Request: β”‚
β”‚ { β”‚
β”‚ "templateType": "invoice", β”‚
β”‚ "templateData": { ... } β”‚
β”‚ } β”‚
β”‚ β”‚
β”‚ Response: β”‚
β”‚ { β”‚
β”‚ "filename": "invoice.pdf", β”‚
β”‚ "content": "JVBERi0x...", ← COPY! β”‚
β”‚ "mimeType": "application/pdf" β”‚
β”‚ } β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
↓
COPY THE BASE64 CONTENT
↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ STEP 2: Send Email with PDF β”‚
β”‚ POST /communications/send β”‚
β”‚ β”‚
β”‚ Request: β”‚
β”‚ { β”‚
β”‚ "recipientContact": "email@...", β”‚
β”‚ "channel": "email", β”‚
β”‚ "subject": "Invoice", β”‚
β”‚ "attachments": [ β”‚
β”‚ { β”‚
β”‚ "filename": "invoice.pdf", β”‚
β”‚ "content": "PASTE_HERE", ← PASTEβ”‚
β”‚ "mimeType": "application/pdf" β”‚
β”‚ } β”‚
β”‚ ] β”‚
β”‚ } β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
↓
EMAIL SENT WITH PDF!
↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Gmail Inbox: β”‚
β”‚ πŸ“§ Subject: Invoice β”‚
β”‚ πŸ“Ž Attachment: invoice.pdf (12 KB) β”‚
β”‚ β”‚
β”‚ [Open] [Download] βœ… β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”§ WHY DID VALIDATION PASS?​

The AttachmentDto allows content to be optional:

export class AttachmentDto {
@IsString()
@IsNotEmpty()
filename!: string; // Required

@IsString()
@IsOptional()
content?: string; // Optional ← This is why!

@IsString()
@IsOptional()
mimeType?: string; // Optional
}

So the validation passed even though content was empty!

Future improvement: We could make content required, but that would break the flexibility of supporting both file URLs and base64 content.


πŸš€ HOW TO FIX IT​

Option 1: Use the Automated Test Script​

# Run the complete workflow automatically
./docs/Multi-Channel-Communication-System/TEST-PDF-WORKFLOW.sh

This script:

  1. βœ… Generates the PDF
  2. βœ… Extracts the base64 content
  3. βœ… Sends the email with the PDF
  4. βœ… Verifies it worked

Option 2: Manual (2 Steps)​

# Step 1: Generate PDF and save content
curl -X POST 'http://localhost:4000/communications/generate-pdf' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-d '{
"templateType": "invoice",
"templateData": {
"invoiceNumber": "INV-431",
"companyName": "RPA Solution",
"customerName": "John Doe",
"totalAmount": "$500.00"
}
}' | jq -r '.content' > pdf-base64.txt

# Step 2: Send with that content
PDF_CONTENT=$(cat pdf-base64.txt)

curl -X POST 'http://localhost:4000/communications/send' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-d '{
"businessId": "33b6db4b-51c5-45ee-8d04-c01c2d157f66",
"createdBy": "6c0c4f32-d74a-4a84-892f-3bead447d765",
"recipientContact": "luisrangelc@gmail.com",
"channel": "email",
"type": "invoice",
"subject": "Invoice #431 - WITH REAL PDF!",
"content": "<p>PDF is attached!</p>",
"attachments": [{
"filename": "invoice-431.pdf",
"content": "'"$PDF_CONTENT"'",
"mimeType": "application/pdf"
}]
}'

πŸ“‹ VERIFICATION CHECKLIST​

After sending, verify:

  • Email received in Gmail
  • Subject line is correct
  • Attachment icon πŸ“Ž is visible
  • Attachment has correct filename (invoice-431.pdf)
  • Attachment has size (not 0 KB)
  • Can click "Download" button
  • PDF opens correctly
  • PDF shows the invoice data

πŸŽ‰ EXPECTED RESULT​

In Gmail:​

πŸ“§ From: RPA <info@rpasolution.com>
To: luisrangelc@gmail.com
Subject: Invoice #431 - WITH REAL PDF!

PDF is attached!

πŸ“Ž invoice-431.pdf (15 KB) [Download]

When you click the PDF:​

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ INVOICE β”‚
β”‚ #INV-431 β”‚
β”‚ β”‚
β”‚ RPA Solution β”‚
β”‚ Customer: John Doe β”‚
β”‚ β”‚
β”‚ Total: $500.00 β”‚
β”‚ β”‚
β”‚ [Invoice details here] β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ” HOW TO DEBUG​

Check if PDF was generated:​

curl -X POST 'http://localhost:4000/communications/generate-pdf' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-d '{"templateType":"invoice","templateData":{"invoiceNumber":"TEST"}}' \
| jq '.content' | wc -c

Expected: Should show a large number (e.g., 15000+ characters)
If it shows 0 or "null": PDF generation failed!

Check attachment in database:​

curl -X GET 'http://localhost:4000/communications/COMM_ID/attachments' \
-H 'Authorization: Bearer YOUR_TOKEN' | jq '.'

Expected: Should show attachment records
If empty: Attachments weren't saved to DB


βœ… SUMMARY​

Problem: Empty attachment
Cause: Missing base64 content in request
Solution: Call /generate-pdf first, then include the base64 in /send
Status: Fixed with new workflow and test script

Try the test script now! πŸš€

./docs/Multi-Channel-Communication-System/TEST-PDF-WORKFLOW.sh

Document Version: 1.0
Last Updated: November 5, 2025, 12:30 PM
Status: βœ… Issue identified and resolved