✅ CORRECT Way to Send Email with PDF
What went wrong: You sent the attachment structure but not the actual PDF content (base64)
The fix: Follow these exact steps
🎯 STEP 1: Generate PDF
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-TEST-001",
"invoiceDate": "2025-11-05",
"companyName": "RPA Solution",
"customerName": "John Doe",
"totalAmount": "$999.00"
}
}' | jq '.'
Response (SAVE THIS!):
{
"filename": "invoice-2025-11-05-temp123.pdf",
"content": "JVBERi0xLjQKJe...VERY_LONG_BASE64_STRING...==",
"mimeType": "application/pdf",
"sizeBytes": 12345
}
🎯 STEP 2: Copy the content Value
From the response above, copy the ENTIRE content value.
Example:
JVBERi0xLjQKJe...VERY_LONG_BASE64_STRING...==
This is the base64-encoded PDF. IT MUST NOT BE EMPTY!
🎯 STEP 3: Send Email (Paste the Base64)
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",
"channel": "email",
"type": "invoice",
"recipientType": "customer",
"recipientId": "824e2bec-8402-4846-b974-1fd543fa2cb1",
"recipientContact": "luisrangelc@gmail.com",
"subject": "TEST: Invoice with REAL PDF",
"content": "<p>Invoice attached</p>",
"attachments": [
{
"filename": "invoice.pdf",
"content": "PASTE_THE_ENTIRE_BASE64_FROM_STEP_1_HERE",
"mimeType": "application/pdf"
}
]
}'
⚠️ CRITICAL: Replace PASTE_THE_ENTIRE_BASE64_FROM_STEP_1_HERE with the actual base64 string from step 1!
❌ WHAT YOU DID WRONG BEFORE
Looking at your .eml file, the attachment was empty:
Content-Disposition: attachment; filename="attachment"
Content-Transfer-Encoding: base64
Content-Type: application/octet-stream; name="attachment"
← EMPTY! No base64 content here!
--boundary--
This happened because:
- You didn't call
/generate-pdffirst - OR you didn't copy the base64 content
- OR you sent empty
content: ""
✅ WHAT IT SHOULD LOOK LIKE
When you do it correctly, the .eml file should show:
Content-Disposition: attachment; filename="invoice.pdf"
Content-Transfer-Encoding: base64
Content-Type: application/pdf
JVBERi0xLjQKJeLjz9MyCjYgMCBvYmoKPDwvTGluZWFyaXplZCAxL0wgMzQ2NzQvTyA4L0Ug
MjEzNjQvTiAxL1QgMzQzODUvSCBbIDUxNiAxNTRdPj4KZW5kb2JqCiAgICAgICAgICAgICAg
... (MANY MORE LINES OF BASE64) ...
--boundary--
See the difference? The base64 content is actually there!
🚀 AUTOMATED TEST SCRIPT
I created a script that does all 3 steps automatically:
# Make it executable
chmod +x docs/Multi-Channel-Communication-System/TEST-PDF-WORKFLOW.sh
# Run it
./docs/Multi-Channel-Communication-System/TEST-PDF-WORKFLOW.sh
This script:
- ✅ Calls
/generate-pdf - ✅ Extracts the base64 content
- ✅ Calls
/sendwith the PDF - ✅ Verifies it was sent
📋 CHECKLIST
Before sending:
- Called
/generate-pdfendpoint - Got response with
contentfield - Verified
contentis NOT empty - Copied the ENTIRE base64 string
- Pasted it into the
attachments[0].contentfield - Sent the email
- Checked Gmail for PDF attachment
🎉 EXPECTED RESULT
Gmail should show:
- ✅ Email received
- ✅ Has attachment icon 📎
- ✅ Attachment is named "invoice.pdf"
- ✅ Attachment can be opened
- ✅ PDF displays correctly
🔧 TROUBLESHOOTING
Problem: "Attachment is empty"
Solution: You didn't include the base64 content. Follow steps 1-3 above.
Problem: "content is null"
Solution: PDF generation failed. Check backend logs.
Problem: "Invalid base64"
Solution: You copied it incorrectly. Use jq -r '.content' to get raw value.
Problem: "Email sent but no attachment"
Solution: The content field was empty. Make sure you paste the base64 from step 1.
💡 PRO TIP
Save the base64 to a file for easier handling:
# Step 1: Generate and save
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-001"}}' \
| jq -r '.content' > pdf-content.txt
# Step 2: Send with file content
PDF_CONTENT=$(cat pdf-content.txt)
curl -X POST 'http://localhost:4000/communications/send' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_TOKEN' \
-d '{
"businessId": "...",
"recipientContact": "test@example.com",
"channel": "email",
"type": "invoice",
"subject": "Invoice",
"content": "PDF attached",
"attachments": [{
"filename": "invoice.pdf",
"content": "'"$PDF_CONTENT"'",
"mimeType": "application/pdf"
}]
}'
✅ TRY AGAIN
- Restart your backend (to load the cleaned-up code)
- Run the test script OR follow the manual steps
- Check Gmail
- The PDF should be there! 🎉
This time it will work! 🚀