DEV Community

Prajwol Shrestha
Prajwol Shrestha

Posted on

Automatically Post Incoming Emails with attachments to Facebook Using n8n

I kept doing the same thing over and over:

an email arrives → copy the subject → download attachments → convert attachments to images → post to Facebook.

After the third or fourth time, I stopped and automated it with n8n.

Now, whenever a new email lands in a specific mailbox, it automatically becomes a Facebook post — attachments included.

This post is a quick breakdown of what I built, why I made certain choices, and what actually worked for me.


What This Automation Does

  • Watches an email inbox
  • Uses the email subject as the Facebook caption
  • Converts and uploads image attachments
  • Publishes the post automatically

Workflow Overview

High-level view of the email → Facebook automation workflow

High-level view of the email → Facebook automation workflow


Why IMAP (and Not the Gmail Trigger)

I initially tried using n8n’s Gmail Trigger because it felt like the more “native” option.

In practice, it wasn’t reliable enough for my use case:

  • New emails didn’t always trigger the workflow
  • Occasionally, nothing fired at all

For an automation that posts publicly, missing even one email isn’t acceptable.

I switched to IMAP for a few practical reasons:

  • Consistent execution — new emails were picked up every time
  • Works with any email provider — not locked into Gmail's API

It’s simple, reliable, and kept the workflow firing every time — exactly what I needed.


Handling Facebook Image Posts

Facebook doesn’t let you upload multiple images directly in a single post.

Instead, you have to:

  1. Upload each image as unpublished
  2. Collect the returned media_fbids
  3. Attach those IDs when creating the final post

Here's what that looks like in n8n:

Step 1: Loop through attachments

  • Use a Loop Over Items node to process each attachment individually

Step 2: Upload as unpublished

  • Endpoint: /{page-id}/photos
  • Method: POST
  • Set published: false and pass the attachment URL

Each upload returns a media_fbid — save these.

Step 3: Create the final post

  • Endpoint: /{page-id}/feed
  • Use the email subject as the message
  • Attach all the media_fbids you collected

Once I understood this flow, the rest was straightforward.


Gotchas I Ran Into

Attachment format matters

n8n treats email attachments as binary data. I had to use the Convert to File node before uploading to Facebook, otherwise the API rejected them

Facebook permissions

Make sure your app has pages_manage_posts and pages_read_engagement permissions, or uploads will fail.


Final Thoughts

This isn’t a flashy automation — but it quietly saves time and removes friction.

If you’re already using n8n and dealing with repetitive posting, this kind of workflow is absolutely worth building.

Sometimes the best automations are the ones you don’t even notice anymore.

Top comments (0)