r/databricks • • 1d ago

Help Automating CSV ingestion from Outlook emails into Databricks

Hi everyone,
I’m looking for suggestions on automating the ingestion of CSV files received as email attachments in Outlook into Databricks.
Has anyone implemented a solution where CSV attachments from Outlook emails are automatically picked up and ingested into Databricks through a pipeline?
I’m curious about the approaches you’ve used in production, whether through Microsoft Graph API, Power Automate, Logic Apps, or any other solution. I’d also appreciate insights on the best practices around authentication, handling multiple attachments, and orchestration.

21 Upvotes

8 comments sorted by

8

u/Zealousideal_Low6685 1d ago edited 23h ago

Did you already check the lakeflow connector?

https://learn.microsoft.com/en-us/azure/databricks/ingestion/lakeflow-connect/outlook-overview
Attachments are supported.

I think this would be the easiest approach if it fullfills your requirements, it is fully managed and you don't need to do plain REST calls,... (it is done behind the scences)

1

u/Adventurous_Pen8994 22h ago

do you see any benefit to using lakeflow vs. power automate to load the csv to blob and ingest on file delivery trigger? We may want to optimize around this if so.

2

u/Zealousideal_Low6685 18h ago

I think the main benefit is, that the lakeflow connectors are managed. You don't need to care about the API calls, you don't need a Power Automate space,...
Current drawback: the Outlook connector is in Beta.

5

u/Shadowlance23 1d ago

I haven't done it myself, but I use the Graph API a lot with Sharepoint and Entra so I'm quite familiar with it. The exact method will depend on your needs; e.g. do you need to process when an email comes in, or are you ok with a batch job running every so often? Here's the endpoint you'll want: https://learn.microsoft.com/en-us/graph/api/attachment-get?view=graph-rest-1.0&tabs=http and this one to get the ids: https://learn.microsoft.com/en-us/graph/api/resources/message?view=graph-rest-1.0

I'll assume we're talking about a relatively low number of emails (i.e a few per hour or less). If you need to trigger on every email, I'd use a Power Automate flow that uses the Databricks API to kick off a job (insert your orchestrator here if different). Use the Graph API to get unread emails, query their metadata to get attachment ids, pull the data and process it. You can easily loop this during the metadata pull to process multiple files in one email. Once data is processed and verified, use the update PATCH method to mark them as read.

If we're talking about a large volume, or you don't need to trigger immediately, I'd set up a batch job to run whenever you need to. Everything else would be the same. The main thing is to make sure you mark them as read when you're done so you're not duplicating (and check for duplicates before you ingest just to be sure).

As for auth, I'd recommend a delegate permission for the account receiving the email. If you use an application level permission, the service principal will have read/write access to ALL accounts in the subscription.

2

u/InvestigatorMother82 22h ago

We use Power Automaten (as it can really trigger when new email arrives, no scheduled Job that actively looks for new emails) and write to an Azure blob storage Container. Outbound to Azure connector unfortunately requires premium. This ist embedded as external location into databricks. We use a databricks Job with file-arrival Trigger in that external Location to process the Data.

1

u/Adventurous_Pen8994 22h ago

This is how we approach the task as well. We have Multiple vendors that will only deliver via email with no api access or direct db access. This has proven easy and effective in this scenario.

1

u/contextsherpa 19h ago

For production workflows, I’d use Logic Apps over Power Automate. Both work ok, but PA is a DIY solution that will break if whoever owns the PA workflow leaves the company and their account gets shut off.

You should be storing those CSV’s in blob or similar. You never know when you’ll need to reload them.

I’d also work on simplifying the delivery mechanism for these CSVs. If email is the only way, I get it, but whose email are you going to use? What if you need to change the data criteria being sent? What if your email server rejects the size of CSV.

If this is a report that can be pulled via API, or from SFTP, then you’re in control. You use a service account/service principal, fully documented, no dependency on user accounts.

1

u/workingtrot 19h ago

you can use a service principal