n8n

How to Automate Gmail ESG Audit Responses?

Emails with ESG reports should not sit in the inbox. This automation watches your Gmail for messages about CSRD reporting, reads the attached XHTML file, and sends a clear audit summary back to the sender. It helps sustainability and finance teams close the loop fast without manual review.

Here is how it works. A Gmail trigger checks new mail and an If filter looks for a subject match like CSRD Reporting. The attachment is downloaded, converted from binary to text, and parsed by code to inspect tags and content. An AI Agent with an OpenAI chat model turns the findings into a short email using a structured format for the subject and body. The reply is posted in the same thread so the sender gets feedback right away.

You need Gmail and OpenAI access, plus n8n credentials for both. Set the subject keyword you want, adjust the prompt tone, and choose the output fields you plan to send. Teams that handle supplier ESG files or weekly disclosures can cut review time from about 30 minutes to under 3 minutes and keep a consistent response style across the inbox.

What are the key features?

  • Gmail trigger polls for new messages and starts the flow
  • If node filters by subject text so only CSRD related emails move forward
  • Gmail attachment download grabs the XHTML file from the message thread
  • Extract from file converts the XHTML from binary to readable text
  • Code nodes parse HTML content and build structured audit results
  • OpenAI chat model generates a clear summary based on the audit
  • Structured output parser enforces subject and body fields for clean formatting
  • Gmail reply posts the summary back to the original sender in the same thread

What are the benefits?

  • Reduce manual review from 30 minutes to under 3 minutes per report
  • Automate up to 90% of inbox triage by filtering only relevant emails
  • Keep responses consistent with structured subject and body fields
  • Handle 5 to 10 times more ESG reports without adding staff
  • Connect Gmail and OpenAI to deliver fast, thread-safe replies

How do you set it up?

  1. Import the template into n8n: Create a new workflow in n8n > Click the three dots menu > Select 'Import from File' > Choose the downloaded JSON file.
  2. You'll need accounts with Gmail and OpenAI. See the Tools Required section above for links to create accounts with these services.
  3. Open the Gmail Trigger node, click the credential dropdown, select Create new credential, and follow the on screen steps to connect your Gmail account with OAuth2. Choose the mailbox and set polling to every minute.
  4. In the If node, set the condition to check the email subject contains your chosen keyword such as CSRD Reporting. Adjust case sensitivity if needed.
  5. Open the Gmail Download Attachment node and confirm Download Attachments is enabled. Keep the Message ID expression so it references the incoming email.
  6. Check the HTML from binary node and confirm the binary property name matches the first attachment such as attachment_0.
  7. Open the Extract the HTML code node and verify it maps the binary text into a field named xhtml_content for the next step.
  8. Open the Check the format code node and review the tag parsing logic. Add or remove tags based on your XHTML structure to improve the audit results.
  9. Open the OpenAI Chat Model node, click Create new credential, and paste your OpenAI API key from your OpenAI account API page. Select a supported model.
  10. In the AI Agent node, link the chat model and the structured output parser. Edit the system message to match your brand voice and email style.
  11. Open the Structured Output Parser and confirm the schema includes subject and body fields. Keep field names in sync with the Gmail Reply node.
  12. In the Gmail Reply node, keep the message ID expression so replies stay in the original thread. Set Email Type to text or HTML as needed.
  13. Send a test email to your Gmail inbox with the keyword in the subject and an XHTML attachment. Check the n8n execution log for a successful run and confirm the reply in Gmail.
  14. Troubleshoot: if no attachment is found, confirm the binary property name. If parsing fails, update the tag list or HTML selectors. If the AI step errors, verify your OpenAI API key and model name.

Tools Required

$24 / mo or $20 / mo billed annually to use n8n in the cloud. However, the local or self-hosted n8n Community Edition is free.

Gmail

Sign up

No cost: Personal Gmail (Gmail API has no usage-based pricing; quotas apply)

OpenAI

Sign up

Pay-as-you-go: GPT-5 at $1.25 per 1M input tokens and $10 per 1M output tokens

Credits:
YouTube video

Similar Templates

Join Futurise to access 1,200+ automation templates

Get instant access to ready-made automation workflows for n8n, Make.com, AI agents, and more. Download, customise, and deploy in minutes.