Retrieve Most Recent Email Subject From Particular Sender

Welcome Forums General PowerShell Q&A Retrieve Most Recent Email Subject From Particular Sender

Viewing 1 reply thread
  • Author
    Posts
    • #203102
      Participant
      Topics: 1
      Replies: 0
      Points: 7
      Rank: Member

      Hi all!

      I require some assistance in retrieving the subject of the most recent email from a particular sender.

      The breakdown: Upon creation of a project within a online software app, an email from the app is automatically sent to my inbox. Using Power Automate, I have created a flow that when an email arrives from the particular sender with a particular subject content (using the conditional trigger), an azure automation script is run. I am using powershell (within the azure automation interface) to write a script that creates a MS team:

      Param(
      
          [string]$teamname, #The name of the Team
          [string]$teamowner, #The email address of the owner of the Team
          [string]$teamalias #The bit of the teamname you want to be the URL
      
      )
      
      #Connect to Teams PowerShell
      $cred = Get-AutomationPSCredential -Name "TeamsAdmin"
      $teams = Connect-MicrosoftTeams -Credential $cred
      
      #Create the Team
      $newteam = New-Team -Alias $teamalias -DisplayName $teamname -Owner $teamowner -AccessType Private 
      
      #Return to Flow the new teams GroupID by passing the object as JSON
      write-output $newteam | convertto-json
      
      #Hangup
      Disconnect-MicrosoftTeams

      Instead of inserting parameters such as the name of the team, I am wanting the script to data mine through outlook, find the most recent email from the particular sender AND of a particular subject, then retrieve part of the subject name to use as the team name. The email subject is of the format: “Blah Blah part of subject I want as team name Blah Blah”, unsure whether it would be easier to retrieve the entire subject name then remove the Blah parts later.

      Thanks for any and all assistance!

      • This topic was modified 2 weeks ago by grokkit.
      • This topic was modified 2 weeks ago by grokkit. Reason: please format your code as per the forum posting instructions
    • #203237
      Participant
      Topics: 11
      Replies: 1445
      Points: 1,783
      Helping Hand
      Rank: Community Hero

      Have you looked at EWS?

      https://dev.to/techspence/using-powershell-and-microsoft-ews-managed-api-to-download-attachments-in-exchange-2016-2171

      Not really a fan of Office COM if it can be avoided. The script could be run from anywhere (with EWS installed) versus running on a workstation with Office and Outlook configured.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.