Generate SharePoint Word documents from Outlook emails with OpenAI and Pandoc
Go to WorkflowDescription
Quick overview
This workflow monitors a Microsoft Outlook mailbox for document-generation requests, matches each request to a SharePoint template using OpenAI, converts the filled template to DOCX via a Pandoc service, uploads the result to Microsoft Graph/SharePoint, and replies by email with the document attached.
How it works
Triggers when a new email is received in Microsoft Outlook.
Extracts the sender, subject, and body text, then authorizes the request by checking the sender domain and a required subject/body keyword.
Retrieves a template catalog from a SharePoint list via the Microsoft Graph API and prepares a condensed catalog for matching.
Uses OpenAI to select the best template from the catalog and extract structured fields (for example party names and dates) from the email.
If no suitable template is found, replies in Outlook with a list of available document types and the reason it could not match.
If a template is matched, downloads the template file from SharePoint, uses OpenAI to recreate it as filled GitHub-flavored Markdown, and sends the Markdown to a Pandoc HTTP service to generate a DOCX.
Uploads the generated DOCX back to SharePoint via Microsoft Graph and replies to the original Outlook email with the DOCX attached and a SharePoint link.
Setup
Create and connect Microsoft OAuth2 credentials that can read and reply to Outlook email and access SharePoint via the Microsoft Graph API.
Update the configuration values for siteId, templatesListId, templatesDriveId, outputDriveId, and outputFolderId to point to your SharePoint site, template list, and output folder.
Ensure your SharePoint template list items include the expected fields (at least Title, Aliases, FileId, and FileName) and that the FileId values match the drive item IDs.
Add OpenAI credentials and select the model(s) you want to use for template matching and document filling.
Provide HTTP header auth credentials for your Pandoc conversion endpoint and set pandocUrl and pandocReferenceDoc to your service and reference DOCX.
Requirements
Self-hosted n8n (for community/LangChain nodes).
Microsoft Outlook and Graph API OAuth2 credentials.
OpenAI API key and access to a Pandoc rendering service.
Customization
Modify AI parameters in template-matching nodes to tune field extraction or document types.
Update the sender domain whitelist
Add templates to your SharePoint
Tweak email reply content to fit your organization’s tone.