Outlook send several mail

Hi everyone.

I have created a workflow to classify bills by customer and resend it by mail, it works perfectly but send several mails, they are all the same mails. Mails are sent every minute (trigger node is confugurated every minute).

Even Have tried deleting the mail that triggered the workflow after the workflow finishes with aditional outlook node. Even to I have tried with gmail nodes (recived mail-send mail)



{
  "nodes": [
    {
      "parameters": {},
      "id": "2182a537-0e43-466e-b5e8-1b020ee8462b",
      "name": "Read PDF",
      "type": "n8n-nodes-base.readPDF",
      "position": [
        -760,
        220
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "values": {
          "number": [
            {
              "name": "maxTokenSize",
              "value": 4000
            },
            {
              "name": "replyTokenSize",
              "value": 50
            }
          ],
          "string": [
            {
              "name": "Match on",
              "value": "payslip"
            },
            {
              "name": "Google Drive folder to upload matched PDFs",
              "value": "https://drive.google.com/drive/u/0/folders/1SKdHTnYoBNlnhF_QJ-Zyepy-3-WZkObo"
            }
          ]
        },
        "options": {}
      },
      "id": "55aef9e0-de8a-454a-86b7-cd5574ca1182",
      "name": "Configure",
      "type": "n8n-nodes-base.set",
      "position": [
        -1640,
        320
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $binary.data.fileExtension }}",
              "value2": "pdf"
            }
          ]
        }
      },
      "id": "91e71134-c64d-4582-b66c-6e7b86f8fd64",
      "name": "Is PDF",
      "type": "n8n-nodes-base.if",
      "position": [
        -980,
        320
      ],
      "typeVersion": 1
    },
    {
      "parameters": {},
      "id": "0fc8d945-3ecf-4ac2-90f0-960d06895b02",
      "name": "Not a PDF",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -760,
        420
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "jsCode": "// https://community.n8n.io/t/iterating-over-email-attachments/13588/3\nlet results = [];\n\nfor (const item of $input.all()) {\n  for (key of Object.keys(item.binary)) {\n        results.push({\n            json: {},\n            binary: {\n                data: item.binary[key],\n            }\n        });\n    }\n}\n\nreturn results;"
      },
      "id": "b6a13ada-0227-4951-bdad-5e979fb218c2",
      "name": "Iterate over email attachments",
      "type": "n8n-nodes-base.code",
      "position": [
        -1200,
        220
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.hasAttachments }}",
              "value2": true
            }
          ]
        }
      },
      "id": "08671a3f-0ca5-450a-9404-27ef45b6ccfd",
      "name": "Has attachments?",
      "type": "n8n-nodes-base.if",
      "position": [
        -1420,
        320
      ],
      "typeVersion": 1
    },
    {
      "parameters": {},
      "id": "767d90e5-4102-4a96-ac5b-15816300f335",
      "name": "There are no attachments",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -1200,
        420
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "filters": {},
        "options": {
          "downloadAttachments": true
        }
      },
      "type": "n8n-nodes-base.microsoftOutlookTrigger",
      "typeVersion": 1,
      "position": [
        -1880,
        340
      ],
      "id": "1951234b-1973-424e-9c43-6f96d5204921",
      "name": "Microsoft Outlook Trigger",
      "credentials": {
        "microsoftOutlookOAuth2Api": {
          "id": "i5BQkfwjaW1y65IZ",
          "name": "Microsoft Outlook account"
        }
      }
    },
    {
      "parameters": {
        "schemaType": "manual"
      },
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.2,
      "position": [
        -380,
        480
      ],
      "id": "617d3bc0-44f0-400e-b382-f6e660af1514",
      "name": "Structured Output Parser"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        -520,
        440
      ],
      "id": "e6cb948a-2ed3-4e53-8caf-bf52f155a6f0",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "id": "oVAfSAd5QFsUwqOq",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "aec67a6e-ded2-49b2-894c-461e62210e58",
              "leftValue": "={{ $json.output.state }}",
              "rightValue": "Factura",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {
          "ignoreCase": false
        }
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -240,
        220
      ],
      "id": "ee5a5b47-0be0-420d-afa3-b7e9536d95eb",
      "name": "If"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        100,
        420
      ],
      "id": "70534f36-7f29-49d4-96b6-168c00bdd6df",
      "name": "OpenAI Chat Model1",
      "credentials": {
        "openAiApi": {
          "id": "oVAfSAd5QFsUwqOq",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.text }}",
        "hasOutputParser": true,
        "messages": {
          "messageValues": [
            {
              "type": "HumanMessagePromptTemplate",
              "message": " Objetivo: Distinguir entre los siguientes tipos de documentos en formato PDF:  Facturas (documentos que detallan una transacción comercial con montos, impuestos, datos del proveedor/cliente).  Órdenes de compra (solicitudes formales de compra con números de pedido, descripción de productos/servicios, condiciones). Complementos de pago (documentos que ajustan o complementan un pago previo, como notas de crédito/débito). Analiza el texto del PDF (incluyendo encabezados, tablas, campos clave y estructura).  Identifica patrones clave para cada tipo: Factura: Busca términos como \"Factura\", \"RFC\", \"Subtotal\", \"IVA\", \"Folio Fiscal\", \"Fecha de emisión\", \"Condiciones de pago\". Orden de compra: Busca frases como \"Orden de Compra\", \"Solicitante\", \"Proveedor\", \"Número de PO\", \"Entrega a\", \"Partidas/Items\".  Complemento de pago: Busca \"Complemento\", \"Nota de crédito/débito\", \"Referencia a factura previa\", \"Ajuste\", \"Saldo pendiente\". Ademas identifica el cliente y el numero de factura  en la salida solo tienes que dar como resultado el tipo de documento del que se trata y el cliente a la que pertenece la factura"
            }
          ]
        }
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.5,
      "position": [
        -580,
        180
      ],
      "id": "ffd49d8a-2ea7-4d4d-a962-81e8d3d43a86",
      "name": "Selección Documeto-Cliente"
    },
    {
      "parameters": {
        "toRecipients": "[email protected]",
        "subject": "={{ $('Microsoft Outlook Trigger').item.json.subject }}",
        "bodyContent": "={{ $json.text }}",
        "additionalFields": {
          "attachments": {
            "attachments": [
              {
                "binaryPropertyName": "data"
              }
            ]
          }
        }
      },
      "type": "n8n-nodes-base.microsoftOutlook",
      "typeVersion": 2,
      "position": [
        720,
        220
      ],
      "id": "610b414e-0ef8-40c5-9b5d-33b4b68ef08d",
      "name": "Microsoft Outlook",
      "webhookId": "3d0ea852-f0a3-46f3-9a87-f09b42c9c0e3",
      "credentials": {
        "microsoftOutlookOAuth2Api": {
          "id": "i5BQkfwjaW1y65IZ",
          "name": "Microsoft Outlook account"
        }
      }
    },
    {
      "parameters": {
        "mode": "combine",
        "combineBy": "combineByPosition",
        "options": {}
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3,
      "position": [
        520,
        200
      ],
      "id": "725001c3-3b43-4659-a916-543e807430b4",
      "name": "Merge"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $('Selección Documeto-Cliente').item.json.output.cities[0] }}",
        "hasOutputParser": true,
        "messages": {
          "messageValues": [
            {
              "type": "HumanMessagePromptTemplate",
              "message": "Redacta un correo profesional y conciso donde informo al destinatario que adjunto la factura de un cliente. El nombre del cliente debe ser dinámico, tomado de un nodo anterior en n8n (ejemplo: \"ABB\"). El tono debe ser formal pero cordial.    Estructura sugerida:   - Saludo breve.   - Mensaje principal: indicar que se adjunta la factura del cliente [NombreDelCliente].   - Agradecimiento por el apoyo.   - Despedida simple.    Ejemplo de salida:   \"Asunto: Factura del cliente [NombreDelCliente]    El saludo debe ser generico, por ejemplo \"hola\", \"buen día\",    Adjunto encontrarás la factura del cliente [NombreDelCliente]. De antemano, agradezco tu apoyo.    Quedo al pendiente por cualquier duda.    Saludos,   [Hector Romo]\"  "
            }
          ]
        }
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.5,
      "position": [
        140,
        120
      ],
      "id": "9feb53a7-716f-4a47-9dd9-6da0f2bf1467",
      "name": "Envio de correo"
    }
  ],
  "connections": {
    "Read PDF": {
      "main": [
        [
          {
            "node": "Selección Documeto-Cliente",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Configure": {
      "main": [
        [
          {
            "node": "Has attachments?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is PDF": {
      "main": [
        [
          {
            "node": "Read PDF",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ],
        [
          {
            "node": "Not a PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Iterate over email attachments": {
      "main": [
        [
          {
            "node": "Is PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has attachments?": {
      "main": [
        [
          {
            "node": "Iterate over email attachments",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "There are no attachments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Microsoft Outlook Trigger": {
      "main": [
        [
          {
            "node": "Configure",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Selección Documeto-Cliente",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Selección Documeto-Cliente",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Envio de correo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Envio de correo",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Selección Documeto-Cliente": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Microsoft Outlook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Envio de correo": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "e3eee6a975900bb807f427fe188f32d9f4804d6b57329021b2b0b4ecede351a8"
  }
}
## Share the output returned by the last node
<!-- If you need help with data transformations, please also share your expected output. -->

![image|690x175](upload://m4jd4aXA88lM2hBY8GC3lUShANO.png)


## Information on your n8n setup
- **n8n version :1.86.1 
- **Database (default: SQLite): No data base
- **n8n EXECUTIONS_PROCESS setting (default: own, main):**
- **Running n8n via (VPS DOCKPLOY):**
- **Operating system:Ubuntu


Thank you in advance.

Hi, can you please correctly post your workflow so it displays correctly, thanks,

So as far as I understand:

Your workflow works in itself (classification and sending), but the problem is that every time it schedules (every minute). it fetches again the same mails you already have processed and sends them again?

reg,
J.

Dear jcuypers

I can´t up load my workflow to the post, I pasted it but only code appears.

I really appreciate the time that you took to reply my post. I solved the problem adding a node update the trigger mail as read, and setup the outlook trigger node with a filter “read status - only un read messages”.

Thank you¡

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.