mcnaveen:
your workflow
< {
“name”: “My workflow 4”,
“nodes”: [
{
“parameters”: {
“postProcessAction”: “nothing”,
“format”: “resolved”,
“options”: {
“customEmailConfig”: “[ ["FROM", "[email protected] "], ["SINCE", "16-Jan-2025"] ]”
}
},
“type”: “n8n-nodes-base.emailReadImap”,
“typeVersion”: 2,
“position”: [
-260,
0
],
“id”: “31a6d01f-f806-4139-923c-721ba44848af”,
“name”: “Email Trigger (IMAP)”,
“credentials”: {
“imap”: {
“id”: “MOYGv7u5aSUyGBKG”,
“name”: “IMAP account 2”
}
}
},
{
“parameters”: {
“operation”: “write”,
“fileName”: “/data/EUROFIVE BULLETIN TT-24.pdf”,
“dataPropertyName”: “attachment_0”,
“options”: {
“append”: false
}
},
“type”: “n8n-nodes-base.readWriteFile”,
“typeVersion”: 1,
“position”: [
-80,
0
],
“id”: “cafc8c77-9dc6-4bcc-bc99-008395c3ab80”,
“name”: “Read/Write Files from Disk”,
“alwaysOutputData”: true
},
{
“parameters”: {
“command”: “/home/node/venv/bin/python3 /data/script.py 2>/dev/null\n”
},
“type”: “n8n-nodes-base.executeCommand”,
“typeVersion”: 1,
“position”: [
100,
0
],
“id”: “ccf74b58-73aa-4698-899a-7ed258595b2c”,
“name”: “Execute Python Script”
},
{
“parameters”: {
“jsCode”: “// Vérifiez la structure de l’entrée\nif (!$json || !$json.stdout) {\n throw new Error("La sortie du nœud précédent est vide ou mal formatée.");\n}\n\n// Analysez la sortie JSON brute contenue dans stdout\nlet parsedOutput;\ntry {\n parsedOutput = JSON.parse($json.stdout);\n} catch (error) {\n throw new Error("Erreur lors de l’analyse JSON : " + error.message + "\nContenu brut : " + $json.stdout);\n}\n\n// Vérifiez que la structure attendue existe\nif (!parsedOutput.output_files || !Array.isArray(parsedOutput.output_files)) {\n throw new Error("Le champ ‘output_files’ est introuvable ou mal formaté.");\n}\n\n// Traitez les fichiers et vérifiez les champs nécessaires\nreturn parsedOutput.output_files.map(file => {\n if (!file.pdf || !file.employee || !file.employee.name) {\n console.error("Fichier mal formé :", file);\n throw new Error(Un fichier est mal formé ou manque des champs nécessaires : ${JSON.stringify(file)}
);\n }\n\n return {\n json: {\n pdf: file.pdf,\n employee: file.employee,\n fileContentBase64: file.fileContentBase64,\n },\n };\n});\n”
},
“type”: “n8n-nodes-base.code”,
“typeVersion”: 2,
“position”: [
260,
0
],
“id”: “d42d3edc-0b78-4dc1-843b-5b10a9291e83”,
“name”: “Process Binary Data”
},
{
“parameters”: {
“fromEmail”: “[email protected] ”,
“toEmail”: “={{ $json.email }}”,
“subject”: “Bulletin de Paie”,
“emailFormat”: “both”,
“options”: {
“attachments”: “=[\n {\n "content": "={{$json[‘Binaire’]}}",\n "filename": {{$json[‘filename’]}},\n "type": "application/pdf"\n }\n]”
}
},
“type”: “n8n-nodes-base.emailSend”,
“typeVersion”: 2.1,
“position”: [
980,
120
],
“id”: “abc899c2-59d3-4f56-ae15-721c4fb56487”,
“name”: “Send Email”,
“executeOnce”: false,
“alwaysOutputData”: true,
“credentials”: {
“smtp”: {
“id”: “Gt5UFapksHzu7IjQ”,
“name”: “SMTP account”
}
}
},
{
“parameters”: {
“mode”: “runOnceForEachItem”,
“jsCode”: “// Loguez les données transmises au nœud Send Email\nconsole.log("Données transmises à Send Email :", $json);\n\n// Transmettez les données sans modification\nreturn $json;\n”
},
“type”: “n8n-nodes-base.code”,
“typeVersion”: 2,
“position”: [
400,
0
],
“id”: “a0be684b-2d2d-49e1-8cdc-b27a561adc3c”,
“name”: “Code1”
},
{
“parameters”: {
“assignments”: {
“assignments”: [
{
“id”: “d9acdf5f-1f18-4db4-b4a0-774337217623”,
“name”: “Binaire”,
“value”: “={{$json["fileContentBase64"]}}”,
“type”: “string”
},
{
“id”: “d08f0ff5-7a62-4fb9-8c6a-c0b250f77ee0”,
“name”: “filename”,
“value”: “={{$json["employee"].name}}_bulletin.pdf”,
“type”: “string”
},
{
“id”: “08f5cd17-e49c-44cf-8beb-339598971b68”,
“name”: “Type MIME”,
“value”: “="application/pdf"”,
“type”: “string”
},
{
“id”: “604a409f-78b9-4cdc-9dca-77b217f3a0b1”,
“name”: “name”,
“value”: “={{$json["employee"].name}}”,
“type”: “string”
}
]
},
“options”: {}
},
“type”: “n8n-nodes-base.set”,
“typeVersion”: 3.4,
“position”: [
540,
0
],
“id”: “f754ef15-c625-4b91-a187-ed9767748b2d”,
“name”: “Edit Fields”
},
{
“parameters”: {
“mode”: “combine”,
“fieldsToMatchString”: “name”,
“options”: {}
},
“type”: “n8n-nodes-base.merge”,
“typeVersion”: 3,
“position”: [
780,
120
],
“id”: “bf52d610-ed82-4a1b-ba2b-6179452c29aa”,
“name”: “Merge”
},
{
“parameters”: {
“url”: “https://rhapi.eurofive.net/employees ”,
“options”: {}
},
“type”: “n8n-nodes-base.httpRequest”,
“typeVersion”: 4.2,
“position”: [
400,
220
],
“id”: “5afa1a31-2b7d-4ab1-a232-c9131f62e2a9”,
“name”: “HTTP Request”
}
],
“pinData”: {},
“connections”: {
“Email Trigger (IMAP)”: {
“main”: [
[
{
“node”: “Read/Write Files from Disk”,
“type”: “main”,
“index”: 0
}
]
]
},
“Read/Write Files from Disk”: {
“main”: [
[
{
“node”: “Execute Python Script”,
“type”: “main”,
“index”: 0
}
]
]
},
“Execute Python Script”: {
“main”: [
[
{
“node”: “Process Binary Data”,
“type”: “main”,
“index”: 0
}
]
]
},
“Process Binary Data”: {
“main”: [
[
{
“node”: “Code1”,
“type”: “main”,
“index”: 0
}
]
]
},
“Code1”: {
“main”: [
[
{
“node”: “Edit Fields”,
“type”: “main”,
“index”: 0
}
]
]
},
“Edit Fields”: {
“main”: [
[
{
“node”: “Merge”,
“type”: “main”,
“index”: 0
}
]
]
},
“Merge”: {
“main”: [
[
{
“node”: “Send Email”,
“type”: “main”,
“index”: 0
}
]
]
},
“HTTP Request”: {
“main”: [
[
{
“node”: “Merge”,
“type”: “main”,
“index”: 1
}
]
]
}
},
“active”: false,
“settings”: {
“executionOrder”: “v1”
},
“versionId”: “ec2f0940-1c57-453e-998b-ccb8a668dc72”,
“meta”: {
“templateCredsSetupCompleted”: true,
“instanceId”: “c3fc32a1a14dd7dbe5c2be2dd1400a7ef3bf9bcecb56db439c48528219010816”
},
“id”: “DYGVrTN820v50mJU”,
“tags”:
}>