how can i send report to sharepoint online programatically?

manny juan 21 Reputation points

currently sharepoint legacy allows us to assign an email_id to a folder and any mail sent to that email_id will have its attachment saved into the associated folder with the name specified in the subject field. it conveniently automates our report delivery.
please show the steps how to do this in sharepoint online.

SharePoint Server Management
SharePoint Server Management
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Management: The act or process of organizing, handling, directing or controlling something.
2,794 questions
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 30,751 Reputation points Microsoft Vendor

    Hi @manny juan
    You can use following powershell script to download attachment file to loacal first

    # link to the folder   
    $olFolderPath = "\\\Inbox\MyAlerts"  
    # set the desired file name  
    $attachmentFileName = 'test.txt'  
    # set the location to temporary file  
    $filePath = "$ENV:Temp"  
    # use MAPI name space  
    $outlook = new-object -com outlook.application;   
    $mapi = $outlook.GetNameSpace("MAPI");  
    # set the Inbox folder id  
    $olDefaultFolderInbox = 6  
    $inbox = $mapi.GetDefaultFolder($olDefaultFolderInbox)   
    # access the target subfolder  
    $olTargetFolder = $inbox.Folders | Where-Object { $_.FolderPath -eq $olFolderPath }  
    # load emails  
    $emails = $olTargetFolder.Items  
    # process the emails  
    foreach ($email in $emails) {  
        # format the timestamp  
        $timestamp = $email.ReceivedTime.ToString("yyyyMMddhhmmss")  
        # filter out the attachments  
        $email.Attachments | Where-Object {$_.FileName -eq $attachmentFileName} | foreach {  
            # insert the timestamp into the file name  
            $fileName = $_.FileName  
            $fileName = $fileName.Insert($fileName.IndexOf('.'),$timestamp)  
            # save the attachment  
            $_.saveasfile((Join-Path $filePath $fileName))   

    Then you can upload local file to sharepoint library

    $SiteURL = ""  
    $FilesPath = "C:\Temp"  
    $ServerRelativePath = "/sites/retail/Shared Documents"  
    #Connect to PnP Online  
    Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)  
    #Get All Files from a Local Folder  
    $Files = Get-ChildItem -Path $FilesPath -Force -Recurse  
    #bulk upload files to sharepoint online using powershell  
    ForEach ($File in $Files)  
        Write-host "Uploading $($File.Directory)\$($File.Name)"  
        #upload a file to sharepoint online using powershell - Upload File and Set Metadata  
        Add-PnPFile -Path "$($File.Directory)\$($File.Name)" -Folder $ServerRelativePath -Values @{"Title" = $($File.Name)}  
    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Haoyan Xue_MSFT 19,481 Reputation points Microsoft Vendor

    Hi @manny juan
    Here are steps:

    1. Create a flow ->select the trigger “When a new email arrives in a shared mailbox”-> Type in the shared mailbox id and Attachments options to Yes.
    2. Add another action “Create File”
      The verification results are as follows:
    3. send a mail to shared mailbox with attchment
    4. wait for a minutes and then check the flow->Succeeded
    5. flow automatically saves its attachment to SharePoint with the name specified in the subject field

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

  2. manny juan 21 Reputation points

    nobody has updated me with a solution or a workaround. it will be a problem for our team because sharepoint online doesn't seem to have an easy way to submit reports programatically. currently in sharepoint legacy, we assigned an email, eg. .com to our destination folder, profit_n_loss. if we create an email (with destination to .com, and a subject "aug2022.csv" the attachment will be saved under the name "aug2022.csv" in the folder named profit_n_loss! (no human intervention required).

    the way it looks we might end up uploading all our reports by hand!

  3. manny juan 21 Reputation points

    that seems like it might work. however, i failed to mention that our application runs on the mainframe (s390) and we don't have power automate. but we have powershell. and we have autosys (a scheduling system for mainframes). is a powershell solution possible? can a powershell script send a report to sharepoint directly? i'm thinking maybe our mainframe job can programmaticaly write the powershell script with the imporant args populated (input file path, shareware destination, etc) with a unique name. autosys can be setup to recognize the arrival of that file (the script) and whe that happens , it runs it. the powershell runs and it performs the transfer. is this doable? thanks

    0 comments No comments