Copy Email From Office 365 To SharePoint Library

Introduction 

 
Hi guys, sometimes we may come across the scenario where we want to copy email (.eml file) from Office o365 to Sharepoint library. This article will help you to solve this scenario.
 
We have to follow these steps to achieve the above requirement:
  • Read emails from the Office O365 account.
  • Extract the emails to the local directory in .eml file format.
  • Upload the extracted .eml file to SharePoint library files.
  • Moved the read emails to another folder in the o365 account from the inbox.
  • Finally, delete the extracted files from local directory 
We can execute the above steps with the help of:
  • Using Powershell Script
  • Using MS Flow 
Before starting with any methods, create one folder inside inbox in office o365 account and one library(Test) in SharePoint online to upload the .eml file.
 
Copy Email From Office 365 To SharePoint Library
 

Using PowerShell Script

 
The PowerShell script requires the following library files.
 
It requires EWS Managed API 2.2, which can be download and install from here
 
It requires a SharePoint Online SDK, which can be downloaded and install from here.
 
Store the credentials of office 365 account and SharePoint online account in the files and read the credentials in the script from the same files. To create and use the credentials in the script in a file and another way, refer my article Passing Credentials in SharePoint Online Using PowerShell
 
Firstly, import and refer the downloaded library files in your script like this.
  1. #Add dll files  
  2. Import-Module -Name "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll"  
  3.   
  4. #Load SharePoint CSOM Assemblies  
  5. Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"  
  6. Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"  
Read the emails from office o365 account:
  1. <#  
  2.     This function is used to read emails from particular emails  
  3. #>  
  4. Function ReadEmails() {  
  5.   param(  
  6.     [Parameter(Mandatory = $true)] $SiteURL,  
  7.     [Parameter(Mandatory = $true)] $USER_DEFINED_FOLDER_IN_MAILBOX  
  8.   )  
  9.   If(!(test-path $exportPath))  
  10.   {  
  11.     Write-Host "Path doesn't exist $($exportPath), Hence creating the path." -f Red  
  12.     New-Item -ItemType Directory -Force -Path $exportPath  
  13.   }  
  14.   $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService  
  15.   $service.Credentials = New-Object System.Net.NetworkCredential -ArgumentList $fileCred.UserName, $fileCred.Password  
  16.   $service.URL = New-Object Uri("https://outlook.office365.com/EWS/Exchange.asmx")  
  17.   # create Property Set to include body and header of email  
  18.   $PropertySet = New-Object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)  
  19.   
  20.   # set email body to text  
  21.   $PropertySet.RequestedBodyType = [Microsoft.Exchange.WebServices.Data.BodyType]::Text;  
  22.   
  23.   # Set how many emails we want to read at a time  
  24.   $numOfEmailsToRead = 100  
  25.   
  26.   # Index to keep track of where we are up to. Set to 0 initially.   
  27.   $index = 0  
  28.   # Do/while loop for paging through the folder   
  29.   do {   
  30.     # Set what we want to retrieve from the folder. This will grab the first $pagesize emails  
  31.     $view = New-Object Microsoft.Exchange.WebServices.Data.ItemView($numOfEmailsToRead, $index)   
  32.     # Retrieve the data from the folder   
  33.     $findResults = $service.FindItems([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox, $view)   
  34.     foreach ($item in $findResults.Items) {  
  35.       # load the additional properties for the item  
  36.       $item.Load($propertySet)  
  37.   
  38.       # Output the results  
  39.       $msgProperty = New-Object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.EmailMessageSchema]::MimeContent)  
  40.       $email = [Microsoft.Exchange.WebServices.Data.EmailMessage]::Bind($service, $item.Id, $msgProperty)  
  41.       $fileName = "$($item.Subject)_$($item.DateTimeReceived)"  
  42.       $subject = Remove-InvalidFileNameChars($fileName)  
  43.       $filePath = "$($exportPath)$($subject).eml";  
  44.       Write-Host "File Name:"$filePath  
  45.         
  46.       # Export the file into .eml format  
  47.       Export-EMLFile $filePath $email  
  48.       $fileSize = 0;  
  49.       $currentFile = New-Object System.IO.FileInfo($filePath);  
  50.       #while ($fileSize -ilt $currentFile.Length)#check size is stable or increased  
  51.       #{  
  52.       #$fileSize = $currentFile.Length; #get current size  
  53.       #Start-Sleep -s 60  
  54.       #$currentFile.Refresh(); #refresh length value  
  55.       #}  
  56.         
  57.       # moved the file to destination folder in office 365 email  
  58.       Move-Email $service $item $USER_DEFINED_FOLDER_IN_MAILBOX $fileName     
  59.     }   
  60.     # Increment $index to next block of emails  
  61.     $index += $numOfEmailsToRead  
  62.   } while ($findResults.MoreAvailable) # Do/While there are more emails to retrieve  
  63.   #Upload the file to library after exporting it  
  64. }  
We will check and removed the invalid character in email subject with underscore (_).
  1. #Removes invalid Characters for file names from a string input and outputs the clean string  
  2. #Similar to VBA CleanString() Method  
  3. #Currently set to replace all illegal characters with a hyphen (_)  
  4. Function Remove-InvalidFileNameChars {  
  5.   param(  
  6.     [Parameter(Mandatory = $true, Position = 0)]  
  7.     [String]$Name  
  8.   )  
  9.   return [RegEx]::Replace($Name, "[{0}]" -f ([RegEx]::Escape([String][System.IO.Path]::GetInvalidFileNameChars())), '_')  
  10. }  
Export all the emails from inbox to local directory:
  1. <#  
  2.   This function is used to export the email to .eml files  
  3. #>  
  4. Function Export-EMLFile() {  
  5.   param(  
  6.     [Parameter(Mandatory = $true, Position = 0)]$filePath,  
  7.     [Parameter(Mandatory = $true, Position = 1)]$email  
  8.   )  
  9.   try {  
  10.      Write-Host "Extracting Email file"  
  11.   
  12.     $fs = New-Object System.IO.FileStream($filePath, [System.IO.FileMode]::Create, [System.IO.FileAccess]::Write)  
  13.     $fs.Write($email.MimeContent.Content, 0, $email.MimeContent.Content.Length)  
  14.   }  
  15.   catch {  
  16.     Write-host -Message $_.Exception.Message  
  17.   }  
  18. }  
Upload the extracted .eml files to SharePoint library with this code.
  1. <#  
  2.     This function is used to upload the files into sharepoint library  
  3. #>  
  4. Function Upload-MultipleFile-To-Library() {  
  5.   
  6.   param(  
  7.     [Parameter(Mandatory = $true)][String]$siteUrl,  
  8.     [Parameter(Mandatory = $true)][String]$libraryName,  
  9.     [Parameter(Mandatory = $true)]$folder  
  10.   )  
  11.      
  12.   $Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($spfileCred.UserName, $spfileCred.Password)  
  13.   #Set up the context  
  14.   $Context = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)  
  15.   $Context.Credentials = $Cred  
  16.       
  17.   #Retrieve list    
  18.   $List = $Context.Web.Lists.GetByTitle($libraryName)    
  19.   $Context.Load($List)    
  20.   $Context.ExecuteQuery()    
  21.   Write-Host "Folder" $folder    
  22.   # Upload file    
  23.   Foreach ($File in (Get-ChildItem $folder)) {    
  24.     Write-Host "Uploading File......$($File.FullName)"  
  25.     $FileStream = New-Object IO.FileStream($File.FullName, [System.IO.FileMode]::Open)    
  26.     $FileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation    
  27.     $FileCreationInfo.Overwrite = $true    
  28.     $FileCreationInfo.ContentStream = $FileStream    
  29.     $FileCreationInfo.URL = $File    
  30.     $Upload = $List.RootFolder.Files.Add($FileCreationInfo)    
  31.     $Context.Load($Upload)    
  32.     $Context.ExecuteQuery()    
  33.     $File.Delete()  
  34.       
  35.   }    
  36. }  
Move the read emails from inbox to another folder (i.e Moved folder)
  1. <#  
  2.     This function is used to moved the email from inbox to another folder in office 365  
  3. #>  
  4. Function Move-Email() {  
  5.   param  
  6.   (  
  7.     [Parameter(Mandatory = $true)]$service,  
  8.     [Parameter(Mandatory = $true)]$Item,  
  9.     [Parameter(Mandatory = $true)]$USER_DEFINED_FOLDER_IN_MAILBOX,  
  10.     [Parameter(Mandatory = $true)]$fileName  
  11.   )  
  12.   $FolderId = @();  
  13.   $FolderView = new-object -TypeName Microsoft.Exchange.WebServices.Data.FolderView -ArgumentList (100)  
  14.   $FolderView.Traversal = [Microsoft.Exchange.Webservices.Data.FolderTraversal]::Deep  
  15.   $SearchFilter = new-object -TypeName Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo -ArgumentList ([Microsoft.Exchange.WebServices.Data.FolderSchema]::DisplayName,$USER_DEFINED_FOLDER_IN_MAILBOX)  
  16.   $FindFolderResults = $service.FindFolders([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot,$SearchFilter,$FolderView)  
  17.   if($FindFolderResults.Id) {  
  18.       Write-host "Moving File $($fileName) from Inbox to $($USER_DEFINED_FOLDER_IN_MAILBOX)" -ForegroundColor Yellow  
  19.       $FolderId += $FindFolderResults.Id  
  20.    }  
  21.   $Message = [Microsoft.Exchange.WebServices.Data.EmailMessage]::Bind($service,$Item.Id)  
  22.   $Message.Move($FolderId[0])  
  23. }  
Delete all the .eml files from directory with this line.
  1. Foreach ($File in (Get-ChildItem $folder)) {    
  2.     Write-Host "Deleting File......$($File.FullName)"  
  3.     $File.Delete()  
  4.   }  
The complete powershell script will look like this: 
  1. <#  
  2.     This script will perform the following fuction,  
  3.   
  4.     -> It will export the email from o365 mail to .eml file on local computer directory.  
  5.     -> Once file is available in local directory it will upload the .eml file into SharePoint Library.  
  6.     -> It will delete the files from local directory.  
  7.     -> Finally, It will moved the files from 'Inbox' to another folder in o365 mail box.  
  8.   
  9.     ***************************************************************************************************                                      
  10.                                         Prerequisites  
  11.     ***************************************************************************************************  
  12.           
  13.         1 - The script requires EWS Managed API 2.2, which can be downloaded here:   
  14.             https://www.microsoft.com/en-us/download/details.aspx?id=42951   
  15.   
  16.         2 - The script requires SharePoint Online SDK, Which can be downloaded here:  
  17.             https://www.microsoft.com/en-in/download/details.aspx?id=42038  
  18.           
  19.         3 - TargetFolder has to be created previous to run the Script  
  20.           
  21.         4 - Source and Target folders have to be unique names. No repeated folders in subfolders.  
  22.   
  23.     ***************************************************************************************************  
  24.                                         Required Parameters  
  25.     ***************************************************************************************************  
  26.   
  27.      1. $credPath   
  28.      2. $fileCred                                         
  29.      3. $spCredPath   
  30.      4. $spfileCred   
  31.      5. $SiteURL       
  32.      6. $libraryName   
  33.      7. $exportPath    
  34.      8. $USER_DEFINED_FOLDER_IN_MAILBOX  
  35.   
  36.    
  37.     ***************************************************************************************************  
  38.                                         Created by    : Arvind Kushwaha  
  39.                                         E-mail        : arvind.kushwaha  
  40.                                         Created Date  : 22-05-2020  
  41.                                         version       : 1.0  
  42.     ***************************************************************************************************  
  43. #>  
  44.  
  45. #Add dll files  
  46. Import-Module -Name "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll"  
  47.  
  48. #Load SharePoint CSOM Assemblies  
  49. Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"  
  50. Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"  
  51.  
  52. #Pass Credentials  
  53. $credPath = "D:\Arvind\safe\secret.txt"  
  54. $fileCred = Import-Clixml -path $credpath  
  55.   
  56. $spCredPath = 'Path to SharePoint Online Account Credentials Files'  
  57. $spfileCred = Import-Clixml -path $spCredPath  
  58.   
  59. $SiteURL = "Your Site Url"  
  60. $libraryName = "Your library Name"  
  61. $exportPath = "D:\Arvind\logs\qc\"  
  62.   
  63. $USER_DEFINED_FOLDER_IN_MAILBOX = "Moved"  
  64. $folder = $exportPath  
  65. <#  
  66.     call the function  
  67. #>  
  68. #ReadEmails $SiteURL $USER_DEFINED_FOLDER_IN_MAILBOX  
  69. Upload-MultipleFile-To-Library $SiteURL $libraryName $folder  
  70. <#  
  71.     This function is used to read emails from particular emails  
  72. #>  
  73. Function ReadEmails() {  
  74.   param(  
  75.     [Parameter(Mandatory = $true)] $SiteURL,  
  76.     [Parameter(Mandatory = $true)] $USER_DEFINED_FOLDER_IN_MAILBOX  
  77.   )  
  78.   If(!(test-path $exportPath))  
  79.   {  
  80.     Write-Host "Path doesn't exist $($exportPath), Hence creating the path." -f Red  
  81.     New-Item -ItemType Directory -Force -Path $exportPath  
  82.   }  
  83.   $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService  
  84.   $service.Credentials = New-Object System.Net.NetworkCredential -ArgumentList $fileCred.UserName, $fileCred.Password  
  85.   $service.URL = New-Object Uri("https://outlook.office365.com/EWS/Exchange.asmx")  
  86.   # create Property Set to include body and header of email  
  87.   $PropertySet = New-Object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)  
  88.  
  89.   # set email body to text  
  90.   $PropertySet.RequestedBodyType = [Microsoft.Exchange.WebServices.Data.BodyType]::Text;  
  91.  
  92.   # Set how many emails we want to read at a time  
  93.   $numOfEmailsToRead = 100  
  94.  
  95.   # Index to keep track of where we are up to. Set to 0 initially.   
  96.   $index = 0  
  97.   # Do/while loop for paging through the folder   
  98.   do {   
  99.     # Set what we want to retrieve from the folder. This will grab the first $pagesize emails  
  100.     $view = New-Object Microsoft.Exchange.WebServices.Data.ItemView($numOfEmailsToRead, $index)   
  101.     # Retrieve the data from the folder   
  102.     $findResults = $service.FindItems([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox, $view)   
  103.     foreach ($item in $findResults.Items) {  
  104.       # load the additional properties for the item  
  105.       $item.Load($propertySet)  
  106.  
  107.       # Output the results  
  108.       $msgProperty = New-Object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.EmailMessageSchema]::MimeContent)  
  109.       $email = [Microsoft.Exchange.WebServices.Data.EmailMessage]::Bind($service, $item.Id, $msgProperty)  
  110.       $fileName = "$($item.Subject)_$($item.DateTimeReceived)"  
  111.       $subject = Remove-InvalidFileNameChars($fileName)  
  112.       $filePath = "$($exportPath)$($subject).eml";  
  113.       Write-Host "File Name:"$filePath  
  114.        
  115.       # Export the file into .eml format  
  116.       Export-EMLFile $filePath $email  
  117.       $fileSize = 0;  
  118.       $currentFile = New-Object System.IO.FileInfo($filePath);  
  119.       #while ($fileSize -ilt $currentFile.Length)#check size is stable or increased  
  120.       #{  
  121.       #$fileSize = $currentFile.Length; #get current size  
  122.       #Start-Sleep -s 60  
  123.       #$currentFile.Refresh(); #refresh length value  
  124.       #}  
  125.        
  126.       # moved the file to destination folder in office 365 email  
  127.       Move-Email $service $item $USER_DEFINED_FOLDER_IN_MAILBOX $fileName     
  128.     }   
  129.     # Increment $index to next block of emails  
  130.     $index += $numOfEmailsToRead  
  131.   } while ($findResults.MoreAvailable) # Do/While there are more emails to retrieve  
  132.   #Upload the file to library after exporting it  
  133. }  
  134. #Removes invalid Characters for file names from a string input and outputs the clean string  
  135. #Similar to VBA CleanString() Method  
  136. #Currently set to replace all illegal characters with a hyphen (_)  
  137. Function Remove-InvalidFileNameChars {  
  138.   param(  
  139.     [Parameter(Mandatory = $true, Position = 0)]  
  140.     [String]$Name  
  141.   )  
  142.   return [RegEx]::Replace($Name, "[{0}]" -f ([RegEx]::Escape([String][System.IO.Path]::GetInvalidFileNameChars())), '_')  
  143. }  
  144. #checked file is locked or not  
  145. Function IsFileLocked() {  
  146.   param  
  147.   (  
  148.     [Parameter(Mandatory = $true, Position = 0)][System.IO.FileStream]$fileInfo  
  149.   )  
  150.   [System.IO.FileStream]$stream = $null;  
  151.   
  152.   try {  
  153.     $stream = $fileInfo.Open([System.IO.FileMode]::Open, [System.IO.FileAccess]::Write, [System.IO.FileShare]::None);  
  154.   }  
  155.   catch {  
  156.     return $true;  
  157.   }  
  158.  
  159.   #file is not locked  
  160.   return $false;  
  161. }  
  162. <#  
  163.   This function is used to export the email to .eml files  
  164. #>  
  165. Function Export-EMLFile() {  
  166.   param(  
  167.     [Parameter(Mandatory = $true, Position = 0)]$filePath,  
  168.     [Parameter(Mandatory = $true, Position = 1)]$email  
  169.   )  
  170.   try {  
  171.      Write-Host "Extracting Email file"  
  172.   
  173.     $fs = New-Object System.IO.FileStream($filePath, [System.IO.FileMode]::Create, [System.IO.FileAccess]::Write)  
  174.     $fs.Write($email.MimeContent.Content, 0, $email.MimeContent.Content.Length)  
  175.   }  
  176.   catch {  
  177.     Write-host -Message $_.Exception.Message  
  178.   }  
  179. }  
  180. <#  
  181.     This function is used to upload the files into sharepoint library  
  182. #>  
  183. Function Upload-MultipleFile-To-Library() {  
  184.   
  185.   param(  
  186.     [Parameter(Mandatory = $true)][String]$siteUrl,  
  187.     [Parameter(Mandatory = $true)][String]$libraryName,  
  188.     [Parameter(Mandatory = $true)]$folder  
  189.   )  
  190.      
  191.   $Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($spfileCred.UserName, $spfileCred.Password)  
  192.   #Set up the context  
  193.   $Context = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)  
  194.   $Context.Credentials = $Cred  
  195.      
  196.   #Retrieve list    
  197.   $List = $Context.Web.Lists.GetByTitle($libraryName)    
  198.   $Context.Load($List)    
  199.   $Context.ExecuteQuery()    
  200.   Write-Host "Folder" $folder    
  201.   # Upload file    
  202.   Foreach ($File in (Get-ChildItem $folder)) {    
  203.     Write-Host "Uploading File......$($File.FullName)"  
  204.     $FileStream = New-Object IO.FileStream($File.FullName, [System.IO.FileMode]::Open)    
  205.     $FileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation    
  206.     $FileCreationInfo.Overwrite = $true    
  207.     $FileCreationInfo.ContentStream = $FileStream    
  208.     $FileCreationInfo.URL = $File    
  209.     $Upload = $List.RootFolder.Files.Add($FileCreationInfo)    
  210.     $Context.Load($Upload)    
  211.     $Context.ExecuteQuery()    
  212.     $File.Delete()  
  213.       
  214.   }    
  215. }  
  216. <#  
  217.     This function is used to moved the email from inbox to another folder in office 365  
  218. #>  
  219. Function Move-Email() {  
  220.   param  
  221.   (  
  222.     [Parameter(Mandatory = $true)]$service,  
  223.     [Parameter(Mandatory = $true)]$Item,  
  224.     [Parameter(Mandatory = $true)]$USER_DEFINED_FOLDER_IN_MAILBOX,  
  225.     [Parameter(Mandatory = $true)]$fileName  
  226.   )  
  227.   $FolderId = @();  
  228.   $FolderView = new-object -TypeName Microsoft.Exchange.WebServices.Data.FolderView -ArgumentList (100)  
  229.   $FolderView.Traversal = [Microsoft.Exchange.Webservices.Data.FolderTraversal]::Deep  
  230.   $SearchFilter = new-object -TypeName Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo -ArgumentList ([Microsoft.Exchange.WebServices.Data.FolderSchema]::DisplayName,$USER_DEFINED_FOLDER_IN_MAILBOX)  
  231.   $FindFolderResults = $service.FindFolders([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot,$SearchFilter,$FolderView)  
  232.   if($FindFolderResults.Id) {  
  233.       Write-host "Moving File $($fileName) from Inbox to $($USER_DEFINED_FOLDER_IN_MAILBOX)" -ForegroundColor Yellow  
  234.       $FolderId += $FindFolderResults.Id  
  235.    }  
  236.   $Message = [Microsoft.Exchange.WebServices.Data.EmailMessage]::Bind($service,$Item.Id)  
  237.   $Message.Move($FolderId[0])  
  238. }   

Using MS Flow

 
Open SharePoint online account and navigate to power automate to create the flow.
 
Copy Email From Office 365 To SharePoint Library
 
Now click on Create and select Automated flow.
 
Copy Email From Office 365 To SharePoint Library
 
Write the name of flow and choose the flow trigger action i.e When a new email arrives(V3)
 
Copy Email From Office 365 To SharePoint Library
 
Select the appropriate folder from where the email will be pulled out. (i.e Inbox)
 
Copy Email From Office 365 To SharePoint Library
 
Choose another action by clicking on the plus sign (+) or click on New Step, and select Export email(V2).
 
Copy Email From Office 365 To SharePoint Library
 
Copy Email From Office 365 To SharePoint Library
 
Choose another action i.e Create file and configure the action in this way.
 
*Site Address : The Url of the SharePoint site
*Folder Path: /Document Library Name
*File Name: Write this expression in this field concat(triggerBody()?['Subject'],triggerBody()?['DateTimeReceived'])
*File Content: Body of Email.
 
Copy Email From Office 365 To SharePoint Library
 
Finally, move the email from the inbox to another folder (Moved) with Move email(v2) action.
 
Copy Email From Office 365 To SharePoint Library
 
Copy Email From Office 365 To SharePoint Library
 

Test the flow

 
Send an email to office 365 account for which flow is configured. (i.e I had configured for my account.)
 
Copy Email From Office 365 To SharePoint Library
 
The flow will trigger as soon as you send an email to our configured account and will look like this
 
Copy Email From Office 365 To SharePoint Library
 
Check the moved folder which contains the test email.
 
Copy Email From Office 365 To SharePoint Library
 
Now, check the SharePoint library which contains the .eml files.
 
Copy Email From Office 365 To SharePoint Library
 

Conclusion

 
In these articles, we have seen how to copy the email from an Office O365 account and upload it into the SharePoint library with PowerShell script and MS flow.