Outlook body is blank

Welcome Forums General PowerShell Q&A Outlook body is blank

This topic contains 3 replies, has 2 voices, and was last updated by

 
Participant
2 years, 4 months ago.

  • Author
    Posts
  • #46579

    Participant
    Points: 0
    Rank: Member
    Add-Type -Path "C:\Program Files (x86)\Microsoft\Exchange\Web Services\2.1\Microsoft.Exchange.WebServices.dll"
    
    $EmailAccount = "test@test.com"
    
    #Change the Exchange Version to work with your environment
    $EWS = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2013_SP1)
    
    #Change the “UseDefaultCredentials” to false if you want to specify alternate creds
    #$EWS.UseDefaultCredentials = $false
    
    $EWS.AutodiscoverUrl($EmailAccount)
    
    $inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($ews,[Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox)
    
    $mailitems = $inbox.FindItems(10)  
    
    
    $SEPmail = $mailitems | ? {$_.conversationtopic -like "*Security Alert by Number of Attacked Computers*"}
    

    This will pull up the correct emails, but any email it grabs, the body property is blank..

    If i just do the line below it brings up the sender, subject just fine, but the body is blank. I'm not sure why...if anyone has any suggestions i would greatly appreciate it.

    $inbox.FindItems(10) | select sender, subject, body
    
  • #46591

    Participant
    Points: 21
    Rank: Member

    I believe you have to load each item.

    $emails = $inbox.FindItems(10)
    $emails.load()

    If that doesn't work, explore the methods by piping into gm.. I don't have access to do it right now.

  • #46753

    Participant
    Points: 0
    Rank: Member

    doing a | gm I do see the body property...doing a $mailitems.load I get

    OverloadDefinitions
    -------------------
    void Load(Microsoft.Exchange.WebServices.Data.PropertySet propertySet)
    void Load()
    
    void Load(Microsoft.Exchange.WebServices.Data.PropertySet propertySet)
    void Load()
    
    void Load(Microsoft.Exchange.WebServices.Data.PropertySet propertySet)
    void Load()
    
    void Load(Microsoft.Exchange.WebServices.Data.PropertySet propertySet)
    void Load()
    
    void Load(Microsoft.Exchange.WebServices.Data.PropertySet propertySet)
    void Load()
    
    void Load(Microsoft.Exchange.WebServices.Data.PropertySet propertySet)
    void Load()
    
    void Load(Microsoft.Exchange.WebServices.Data.PropertySet propertySet)
    void Load()
    
    void Load(Microsoft.Exchange.WebServices.Data.PropertySet propertySet)
    void Load()
    
    void Load(Microsoft.Exchange.WebServices.Data.PropertySet propertySet)
    void Load()
    
    void Load(Microsoft.Exchange.WebServices.Data.PropertySet propertySet)
    void Load()
    
  • #46755

    Participant
    Points: 0
    Rank: Member

    You nailed it...I was missing the .load()

    Thanks!!!

The topic ‘Outlook body is blank’ is closed to new replies.