power-automatepower-automate-desktop

Power Automate Flow to monitor shared mailbox & save the email attachment to local folder inside onpremises server


We have a shared mail box, and we need to get the emails received from a specific email address, then get the attachments inside the emails, and save them to local folder inside on-premises server's c drive... mainly c:\temp\sql. The On-premises sever, is actually our SQL server on-premises.

So which approach we need to follow?? I know that I can monitor a shared mailbox inside power automate (cloud), then get the email attachments, but I cannot save them to local server folder... so is creating a power automate desktop to access the local folder a way to go? if so, then can we monitor a shared mailbox using power automate desktop?

Any advice please? Thanks


Solution

  • On Power Automate:

    Save the files on an interim server from power automate for example a sharepoint or one drive folder.

    Setup another HTTP triggered flow, that simply fetches and creates a list of all files in that folder and return as response.

    Then on Server:

    Schedule a task on the server toe execute a powershell script.

    Here's what the script should look like.

    $logicAppUrl = "https://api.com/path"  # Replace with your actual Logic App URL
    
    # Folder to save output files
    $targetFolder = "C:\temp\sql" # Or whatever folder needed
    
    # Create the folder if it doesn't exist
    if (-Not (Test-Path -Path $targetFolder)) {
        New-Item -Path $targetFolder -ItemType Directory
    }
    
    # Send HTTP GET request to the Logic Apphow
    $response = Invoke-WebRequest -Uri $logicAppUrl -Method Get -OutFile $localFilePath
    

    This script sends a GET Request to the Endpoint you had setup and retrieves te list of files. Then it dsaves it to the designated folder. By scheduling it every 5 minutes (or whatever frequency you think is suitable), you can get the files on servers. You can also update the HTTP flow to delete/archive files after being read to avoid redundancy.

    You can add further logic to rename files or even convert types if applicable. It also accepts headers and body if required for paramaterization/auth purposes. GPT can assist with code updates.