{ "kind": "open-flow-workflow", "version": 1, "name": "Send an Outlook Draft with an Attachment", "content": { "modelVersion": 14, "document": { "bindings": {}, "graph": { "nodes": { "n_396ed1f301e67091": { "name": "Start the email", "kind": "start", "inputDefs": [] }, "n_63ca96fb23b2a661": { "inputs": { "subject": { "kind": "value", "value": "Hello from n8n!" }, "body": { "kind": "value", "value": "

Hello from n8n!

We are sending this email using Outlook.

Best,
Sender

" }, "isHtml": { "kind": "value", "value": true }, "toRecipients": { "kind": "value", "value": [ "YOUR_RECIPIENT_EMAIL" ] } }, "name": "Create an Outlook draft", "kind": "task", "task": { "inputs": [ { "description": "Subject line for the draft message.", "jsonSchema": { "type": "string", "description": "Subject line for the draft message." }, "nullable": false, "handle": "subject" }, { "description": "Body content for the draft message.", "jsonSchema": { "type": "string", "description": "Body content for the draft message." }, "nullable": false, "handle": "body" }, { "description": "Whether the draft body is already HTML content.", "jsonSchema": { "type": "boolean", "description": "Whether the draft body is already HTML content." }, "nullable": true, "handle": "isHtml", "value": null }, { "description": "Primary recipients for the draft message.", "jsonSchema": { "type": "array", "items": { "anyOf": [ { "type": "string", "minLength": 1, "description": "Schema for nonEmptyString." }, { "type": "object", "properties": { "address": { "type": "string", "minLength": 1, "description": "Recipient email address." }, "name": { "type": "string", "description": "Recipient display name." } }, "required": [ "address" ], "additionalProperties": false, "description": "Schema for recipientAddressInputSchema." } ], "description": "Recipient email address or recipient object with display name." }, "description": "Primary recipients for the draft message." }, "nullable": true, "handle": "toRecipients", "value": null }, { "description": "Cc recipients for the draft message.", "jsonSchema": { "type": "array", "items": { "anyOf": [ { "type": "string", "minLength": 1, "description": "Schema for nonEmptyString." }, { "type": "object", "properties": { "address": { "type": "string", "minLength": 1, "description": "Recipient email address." }, "name": { "type": "string", "description": "Recipient display name." } }, "required": [ "address" ], "additionalProperties": false, "description": "Schema for recipientAddressInputSchema." } ], "description": "Recipient email address or recipient object with display name." }, "description": "Cc recipients for the draft message." }, "nullable": true, "handle": "ccRecipients", "value": null }, { "description": "Bcc recipients for the draft message.", "jsonSchema": { "type": "array", "items": { "anyOf": [ { "type": "string", "minLength": 1, "description": "Schema for nonEmptyString." }, { "type": "object", "properties": { "address": { "type": "string", "minLength": 1, "description": "Recipient email address." }, "name": { "type": "string", "description": "Recipient display name." } }, "required": [ "address" ], "additionalProperties": false, "description": "Schema for recipientAddressInputSchema." } ], "description": "Recipient email address or recipient object with display name." }, "description": "Bcc recipients for the draft message." }, "nullable": true, "handle": "bccRecipients", "value": null }, { "description": "Reply-to recipients for the draft message.", "jsonSchema": { "type": "array", "items": { "anyOf": [ { "type": "string", "minLength": 1, "description": "Schema for nonEmptyString." }, { "type": "object", "properties": { "address": { "type": "string", "minLength": 1, "description": "Recipient email address." }, "name": { "type": "string", "description": "Recipient display name." } }, "required": [ "address" ], "additionalProperties": false, "description": "Schema for recipientAddressInputSchema." } ], "description": "Recipient email address or recipient object with display name." }, "description": "Reply-to recipients for the draft message." }, "nullable": true, "handle": "replyTo", "value": null }, { "description": "Message importance.", "jsonSchema": { "type": "string", "enum": [ "low", "normal", "high" ], "description": "Message importance." }, "nullable": true, "handle": "importance", "value": null }, { "description": "Categories to apply to the draft.", "jsonSchema": { "type": "array", "items": { "type": "string", "minLength": 1, "description": "Schema for nonEmptyString." }, "description": "Categories to apply to the draft." }, "nullable": true, "handle": "categories", "value": null } ], "outputs": [ { "description": "Outlook message resource.", "jsonSchema": { "type": "object", "properties": { "@odata.etag": { "type": "string", "description": "Entity tag for the message." }, "id": { "type": "string", "description": "Message ID." }, "createdDateTime": { "type": "string", "description": "Timestamp when the message was created." }, "lastModifiedDateTime": { "type": "string", "description": "Timestamp when the message was last modified." }, "changeKey": { "type": "string", "description": "Change key for the message." }, "categories": { "type": "array", "items": { "type": "string", "description": "An array item." }, "description": "Categories applied to the message." }, "receivedDateTime": { "type": "string", "description": "Timestamp when the message was received." }, "sentDateTime": { "type": "string", "description": "Timestamp when the message was sent." }, "hasAttachments": { "type": "boolean", "description": "Whether the message has attachments." }, "internetMessageId": { "type": "string", "description": "Internet message identifier for the message." }, "subject": { "type": "string", "description": "Message subject." }, "bodyPreview": { "type": "string", "description": "Preview snippet of the message body." }, "importance": { "type": "string", "description": "Message importance." }, "parentFolderId": { "type": "string", "description": "Parent folder ID for the message." }, "conversationId": { "type": "string", "description": "Conversation ID for the message." }, "conversationIndex": { "type": "string", "description": "Conversation index for the message." }, "isDeliveryReceiptRequested": { "type": "boolean", "description": "Whether delivery receipts are requested." }, "isReadReceiptRequested": { "type": "boolean", "description": "Whether read receipts are requested." }, "isRead": { "type": "boolean", "description": "Whether the message is marked as read." }, "isDraft": { "type": "boolean", "description": "Whether the message is a draft." }, "webLink": { "type": "string", "description": "Web URL for the message in Outlook." }, "inferenceClassification": { "type": "string", "description": "Outlook inference classification for the message." }, "body": { "type": "object", "properties": { "contentType": { "type": "string", "description": "Message body content type." }, "content": { "type": "string", "description": "Message body content." } }, "required": [ "contentType", "content" ], "additionalProperties": false, "description": "Message body." }, "sender": { "type": "object", "properties": { "emailAddress": { "type": "object", "properties": { "name": { "type": "string", "description": "Display name for the email address." }, "address": { "type": "string", "description": "Email address value." } }, "required": [ "address" ], "additionalProperties": false, "description": "Recipient email address." } }, "required": [ "emailAddress" ], "additionalProperties": false, "description": "Sender of the message." }, "from": { "type": "object", "properties": { "emailAddress": { "type": "object", "properties": { "name": { "type": "string", "description": "Display name for the email address." }, "address": { "type": "string", "description": "Email address value." } }, "required": [ "address" ], "additionalProperties": false, "description": "Recipient email address." } }, "required": [ "emailAddress" ], "additionalProperties": false, "description": "Mailbox owner and sender of the message." }, "toRecipients": { "type": "array", "items": { "type": "object", "properties": { "emailAddress": { "type": "object", "properties": { "name": { "type": "string", "description": "Display name for the email address." }, "address": { "type": "string", "description": "Email address value." } }, "required": [ "address" ], "additionalProperties": false, "description": "Recipient email address." } }, "required": [ "emailAddress" ], "additionalProperties": false, "description": "Recipient object returned by Outlook." }, "description": "Primary recipients." }, "ccRecipients": { "type": "array", "items": { "type": "object", "properties": { "emailAddress": { "type": "object", "properties": { "name": { "type": "string", "description": "Display name for the email address." }, "address": { "type": "string", "description": "Email address value." } }, "required": [ "address" ], "additionalProperties": false, "description": "Recipient email address." } }, "required": [ "emailAddress" ], "additionalProperties": false, "description": "Recipient object returned by Outlook." }, "description": "Cc recipients." }, "bccRecipients": { "type": "array", "items": { "type": "object", "properties": { "emailAddress": { "type": "object", "properties": { "name": { "type": "string", "description": "Display name for the email address." }, "address": { "type": "string", "description": "Email address value." } }, "required": [ "address" ], "additionalProperties": false, "description": "Recipient email address." } }, "required": [ "emailAddress" ], "additionalProperties": false, "description": "Recipient object returned by Outlook." }, "description": "Bcc recipients." }, "replyTo": { "type": "array", "items": { "type": "object", "properties": { "emailAddress": { "type": "object", "properties": { "name": { "type": "string", "description": "Display name for the email address." }, "address": { "type": "string", "description": "Email address value." } }, "required": [ "address" ], "additionalProperties": false, "description": "Recipient email address." } }, "required": [ "emailAddress" ], "additionalProperties": false, "description": "Recipient object returned by Outlook." }, "description": "Reply-to recipients." }, "flag": { "type": "object", "properties": { "flagStatus": { "type": "string", "description": "Follow-up flag status." }, "startDateTime": { "type": "object", "properties": { "dateTime": { "type": "string", "description": "Date and time value." }, "timeZone": { "type": "string", "description": "Time zone identifier for the date and time value." } }, "required": [ "dateTime", "timeZone" ], "additionalProperties": false, "description": "Follow-up start date and time." }, "dueDateTime": { "type": "object", "properties": { "dateTime": { "type": "string", "description": "Date and time value." }, "timeZone": { "type": "string", "description": "Time zone identifier for the date and time value." } }, "required": [ "dateTime", "timeZone" ], "additionalProperties": false, "description": "Follow-up due date and time." }, "completedDateTime": { "type": "object", "properties": { "dateTime": { "type": "string", "description": "Date and time value." }, "timeZone": { "type": "string", "description": "Time zone identifier for the date and time value." } }, "required": [ "dateTime", "timeZone" ], "additionalProperties": false, "description": "Follow-up completion date and time." } }, "additionalProperties": true, "description": "Follow-up flag details." } }, "required": [ "id" ], "additionalProperties": true, "description": "Outlook message resource." }, "nullable": false, "handle": "output" } ], "name": "Create an Outlook draft", "executor": { "kind": "connector", "action": "outlook.create_draft", "outputMode": "value" } } }, "n_97e2bfbf46c5c729": { "inputs": {}, "name": "Download the sample image", "kind": "task", "task": { "inputs": [], "outputs": [ { "jsonSchema": { "type": "string", "minLength": 1 }, "nullable": false, "handle": "name" }, { "jsonSchema": { "type": "string", "minLength": 1 }, "nullable": false, "handle": "mimeType" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "contentBase64" } ], "name": "Download the sample image", "moduleId": "n_e3d0b7f6caa53062", "capabilities": [ { "kind": "http", "hosts": [ "n8n.io" ] } ] } }, "n_2a4f47501e867a51": { "inputs": { "draft": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_63ca96fb23b2a661", "output": "output" } ] }, "name": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_97e2bfbf46c5c729", "output": "name" } ] }, "mimeType": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_97e2bfbf46c5c729", "output": "mimeType" } ] }, "contentBase64": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_97e2bfbf46c5c729", "output": "contentBase64" } ] } }, "name": "Prepare the attachment", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "object", "properties": { "@odata.etag": { "type": "string", "description": "Entity tag for the message." }, "id": { "type": "string", "description": "Message ID." }, "createdDateTime": { "type": "string", "description": "Timestamp when the message was created." }, "lastModifiedDateTime": { "type": "string", "description": "Timestamp when the message was last modified." }, "changeKey": { "type": "string", "description": "Change key for the message." }, "categories": { "type": "array", "items": { "type": "string", "description": "An array item." }, "description": "Categories applied to the message." }, "receivedDateTime": { "type": "string", "description": "Timestamp when the message was received." }, "sentDateTime": { "type": "string", "description": "Timestamp when the message was sent." }, "hasAttachments": { "type": "boolean", "description": "Whether the message has attachments." }, "internetMessageId": { "type": "string", "description": "Internet message identifier for the message." }, "subject": { "type": "string", "description": "Message subject." }, "bodyPreview": { "type": "string", "description": "Preview snippet of the message body." }, "importance": { "type": "string", "description": "Message importance." }, "parentFolderId": { "type": "string", "description": "Parent folder ID for the message." }, "conversationId": { "type": "string", "description": "Conversation ID for the message." }, "conversationIndex": { "type": "string", "description": "Conversation index for the message." }, "isDeliveryReceiptRequested": { "type": "boolean", "description": "Whether delivery receipts are requested." }, "isReadReceiptRequested": { "type": "boolean", "description": "Whether read receipts are requested." }, "isRead": { "type": "boolean", "description": "Whether the message is marked as read." }, "isDraft": { "type": "boolean", "description": "Whether the message is a draft." }, "webLink": { "type": "string", "description": "Web URL for the message in Outlook." }, "inferenceClassification": { "type": "string", "description": "Outlook inference classification for the message." }, "body": { "type": "object", "properties": { "contentType": { "type": "string", "description": "Message body content type." }, "content": { "type": "string", "description": "Message body content." } }, "required": [ "contentType", "content" ], "additionalProperties": false, "description": "Message body." }, "sender": { "type": "object", "properties": { "emailAddress": { "type": "object", "properties": { "name": { "type": "string", "description": "Display name for the email address." }, "address": { "type": "string", "description": "Email address value." } }, "required": [ "address" ], "additionalProperties": false, "description": "Recipient email address." } }, "required": [ "emailAddress" ], "additionalProperties": false, "description": "Sender of the message." }, "from": { "type": "object", "properties": { "emailAddress": { "type": "object", "properties": { "name": { "type": "string", "description": "Display name for the email address." }, "address": { "type": "string", "description": "Email address value." } }, "required": [ "address" ], "additionalProperties": false, "description": "Recipient email address." } }, "required": [ "emailAddress" ], "additionalProperties": false, "description": "Mailbox owner and sender of the message." }, "toRecipients": { "type": "array", "items": { "type": "object", "properties": { "emailAddress": { "type": "object", "properties": { "name": { "type": "string", "description": "Display name for the email address." }, "address": { "type": "string", "description": "Email address value." } }, "required": [ "address" ], "additionalProperties": false, "description": "Recipient email address." } }, "required": [ "emailAddress" ], "additionalProperties": false, "description": "Recipient object returned by Outlook." }, "description": "Primary recipients." }, "ccRecipients": { "type": "array", "items": { "type": "object", "properties": { "emailAddress": { "type": "object", "properties": { "name": { "type": "string", "description": "Display name for the email address." }, "address": { "type": "string", "description": "Email address value." } }, "required": [ "address" ], "additionalProperties": false, "description": "Recipient email address." } }, "required": [ "emailAddress" ], "additionalProperties": false, "description": "Recipient object returned by Outlook." }, "description": "Cc recipients." }, "bccRecipients": { "type": "array", "items": { "type": "object", "properties": { "emailAddress": { "type": "object", "properties": { "name": { "type": "string", "description": "Display name for the email address." }, "address": { "type": "string", "description": "Email address value." } }, "required": [ "address" ], "additionalProperties": false, "description": "Recipient email address." } }, "required": [ "emailAddress" ], "additionalProperties": false, "description": "Recipient object returned by Outlook." }, "description": "Bcc recipients." }, "replyTo": { "type": "array", "items": { "type": "object", "properties": { "emailAddress": { "type": "object", "properties": { "name": { "type": "string", "description": "Display name for the email address." }, "address": { "type": "string", "description": "Email address value." } }, "required": [ "address" ], "additionalProperties": false, "description": "Recipient email address." } }, "required": [ "emailAddress" ], "additionalProperties": false, "description": "Recipient object returned by Outlook." }, "description": "Reply-to recipients." }, "flag": { "type": "object", "properties": { "flagStatus": { "type": "string", "description": "Follow-up flag status." }, "startDateTime": { "type": "object", "properties": { "dateTime": { "type": "string", "description": "Date and time value." }, "timeZone": { "type": "string", "description": "Time zone identifier for the date and time value." } }, "required": [ "dateTime", "timeZone" ], "additionalProperties": false, "description": "Follow-up start date and time." }, "dueDateTime": { "type": "object", "properties": { "dateTime": { "type": "string", "description": "Date and time value." }, "timeZone": { "type": "string", "description": "Time zone identifier for the date and time value." } }, "required": [ "dateTime", "timeZone" ], "additionalProperties": false, "description": "Follow-up due date and time." }, "completedDateTime": { "type": "object", "properties": { "dateTime": { "type": "string", "description": "Date and time value." }, "timeZone": { "type": "string", "description": "Time zone identifier for the date and time value." } }, "required": [ "dateTime", "timeZone" ], "additionalProperties": false, "description": "Follow-up completion date and time." } }, "additionalProperties": true, "description": "Follow-up flag details." } }, "required": [ "id" ], "additionalProperties": true, "description": "Outlook message resource." }, "nullable": false, "handle": "draft" }, { "jsonSchema": { "type": "string", "minLength": 1 }, "nullable": false, "handle": "name" }, { "jsonSchema": { "type": "string", "minLength": 1 }, "nullable": false, "handle": "mimeType" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "contentBase64" } ], "outputs": [ { "jsonSchema": { "type": "string", "minLength": 1 }, "nullable": false, "handle": "id" }, { "jsonSchema": { "type": "string", "minLength": 1 }, "nullable": false, "handle": "endpoint" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "body" } ], "name": "Prepare the attachment", "moduleId": "n_21c543a4c7f206c2", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_8d75ac970f3e4953": { "inputs": { "endpoint": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_2a4f47501e867a51", "output": "endpoint" } ] }, "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_2a4f47501e867a51", "output": "body" } ] } }, "name": "Attach the image", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "endpoint" }, { "jsonSchema": {}, "nullable": true, "handle": "body" } ], "outputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": false, "handle": "headers" }, { "jsonSchema": { "const": "base64" }, "nullable": true, "handle": "bodyEncoding" } ], "name": "Attach the image", "executor": { "providerId": "outlook", "method": "POST", "query": { "mode": "fields", "names": [] }, "headers": { "mode": "fields", "names": [] }, "bodyFormat": "json", "kind": "connector-proxy" } } }, "n_2975db910a4e22b8": { "inputs": { "statusCode": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_8d75ac970f3e4953", "output": "statusCode" } ] }, "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_8d75ac970f3e4953", "output": "body" } ] }, "id": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_2a4f47501e867a51", "output": "id" } ] } }, "name": "Confirm the attachment", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "string", "minLength": 1 }, "nullable": false, "handle": "id" } ], "outputs": [ { "jsonSchema": { "type": "string", "minLength": 1 }, "nullable": false, "handle": "id" } ], "name": "Confirm the attachment", "moduleId": "n_92bde5b8490e0161", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_380136aec0217e6a": { "inputs": { "messageId": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_2975db910a4e22b8", "output": "id" } ] } }, "name": "Send the Outlook draft", "kind": "task", "task": { "inputs": [ { "description": "Outlook message ID.", "jsonSchema": { "type": "string", "minLength": 1, "description": "Outlook message ID." }, "nullable": false, "handle": "messageId" } ], "outputs": [ { "description": "Whether the Outlook operation completed successfully.", "jsonSchema": { "const": true, "description": "Whether the Outlook operation completed successfully." }, "nullable": false, "handle": "success" } ], "name": "Send the Outlook draft", "executor": { "kind": "connector", "action": "outlook.send_draft" } } } }, "edges": [ { "source": "n_396ed1f301e67091", "target": "n_63ca96fb23b2a661" }, { "source": "n_63ca96fb23b2a661", "target": "n_97e2bfbf46c5c729" }, { "source": "n_97e2bfbf46c5c729", "target": "n_2a4f47501e867a51" }, { "source": "n_2a4f47501e867a51", "target": "n_8d75ac970f3e4953" }, { "source": "n_8d75ac970f3e4953", "target": "n_2975db910a4e22b8" }, { "source": "n_2975db910a4e22b8", "target": "n_380136aec0217e6a" } ] } }, "modules": { "n_e3d0b7f6caa53062": { "name": "Download the sample image", "imports": [], "source": "import {Buffer} from 'node:buffer';\nexport default async function download(_input,context){const r=await context.fetch('https://n8n.io/n8n-logo.png');if(!r.ok)throw Error('Attachment download failed; inspect the Outlook draft');const bytes=new Uint8Array(await r.arrayBuffer());if(!bytes.length)throw Error('Empty attachment; inspect the Outlook draft');return{name:'n8n.png',mimeType:'image/png',contentBase64:Buffer.from(bytes).toString('base64')}}\n" }, "n_21c543a4c7f206c2": { "name": "Prepare the attachment", "imports": [], "source": "export default function attachment({draft,name,mimeType,contentBase64}){\n const id=draft?.id;if(typeof id!=='string'||!id)throw Error('Outlook did not confirm draft ID; inspect drafts before retrying');\n return {id,endpoint:'/me/messages/'+encodeURIComponent(id)+'/attachments',body:{'@odata.type':'#microsoft.graph.fileAttachment',name,contentType:mimeType,contentBytes:contentBase64}};\n}\n" }, "n_92bde5b8490e0161": { "name": "Confirm the attachment", "imports": [], "source": "export default function confirm({statusCode,body,id}){if(statusCode!==201||typeof body?.id!=='string'||!body.id)throw Error('Attachment not confirmed; inspect Outlook draft before retrying');return {id};}\n" } } }, "presentation": { "designer": { "version": 1, "flow": { "direction": "vertical" } } } }