Introduction

Many email workflows involve attachments—invoices, receipts, documents, and images that need to be processed automatically. MailWebhook makes it easy to extract and handle these files.

How Attachments Work

When an email with attachments arrives, MailWebhook:

  1. Extracts each attachment from the email
  2. Uploads it to secure cloud storage
  3. Includes download URLs in your webhook payload
{
  "attachments": [
    {
      "filename": "invoice-2026.pdf",
      "content_type": "application/pdf",
      "size": 125000,
      "url": "https://storage.mailwebhook.com/..."
    }
  ]
}

Processing Attachments

Here’s how to handle attachments in your webhook handler:

app.post('/webhooks/email', async (req, res) => {
  const { attachments } = req.body
  
  for (const attachment of attachments) {
    // Download the file
    const response = await fetch(attachment.url)
    const buffer = await response.arrayBuffer()
    
    // Process based on file type
    if (attachment.content_type === 'application/pdf') {
      await processPDF(buffer)
    } else if (attachment.content_type.startsWith('image/')) {
      await processImage(buffer)
    }
  }
  
  res.status(200).json({ processed: true })
})

Security Considerations

  • Attachment URLs expire after 24 hours
  • Always validate file types before processing
  • Scan for malware before storing files permanently

Conclusion

Automating attachment processing can save hours of manual work. With MailWebhook, you get secure, reliable access to email attachments without managing file storage yourself.