You can use this template to setup a workflow that listens in to incoming email messages with attachments and when it gets a hit it will deliver the attachments to an endpoint.
version: "0.2"
addresses:
[email protected]:
keys:
- name: owner
read: true
write: true
accessories:
- name: [email protected]
type: mailscript-email
address: [email protected]
key: owner
workflows:
- name: attachments
trigger: attachments-trigger
action: attachments-webhook-action
triggers:
- name: attachments-trigger
accessory: [email protected]
config:
criterias:
- hasAttachments: true
actions:
- name: attachments-webhook-action
config:
type: webhook
body: |
{
"attachments": "{{msg.attachments}}"
}
url: "https://endpoint.url"
opts:
headers:
Content-Type: application/json
method: POST
Expects body.json
file containing { attachments: "{{msg.attachments}}" }
mailscript workflows:add \
--name "attachments to webhook" \
--trigger [email protected] \
--action webhook \
--webhook "https://endpoint.url" \
--body ./body.json
Example usage to read payload:
const express = require("express")
const fs = require("fs")
const handler = async (req, res) => {
const { attachments } = req.body
for (const attachment of attachments) {
const { filename, content } = attachment
const path = `./files/${filename}`
fs.writeFileSync(path, Buffer.from(content))
}
res.status(200).send({ status: "ok" })
}
const app = express()
app.post("/", express.json(), handler)