none
Read mail from powershell RRS feed

  • Question

  • Hey,

    I want to read an email and after that delete it, using PowerShell

    i need subject and export body to txt file

    Monday, November 13, 2017 12:26 PM

All replies

  • Not sure I follow,  what do you mean read the email, i.e. like you do with outlook or??  Please advise of your situation, why you want to take these actions etc

    Search, Recover, Export Mailboxes, Folders, Email, Contacts, Calendars, Tasks, etc. from Offline Exchange Databases (EDBs), On-Premise Exchange Servers and Office 365. Migrate/Recover direct from any offline EDB into any On-Premises Exchange Server, even cross version i.e. 2003 → 2007 → 2010 →2013 → 2016 → Office 365 with Lucid8's DigiScope

    Monday, November 13, 2017 3:22 PM
  • Hi

    If you are writining about message tracking, you can use this command:

    Get-MessageTrackingLog -Start "11/13/2017 00:00:00" -End "11/13/2017 23:59:59" -recipient "John.doe@contoso.com" | select-object eventid,timestamp,source,messageid,sender,recipients,messagesubject | Out-Gridview


    Monday, November 13, 2017 3:35 PM
  • If you want to export the body of a Message you will need to use a Mailbox API to do this, so your options are to use EWS,MAPI or if you have Office365 use the new REST API. You really need to give more context in your question (eg I want to search for X message based on Y parameter etc and I'm using Z) though i would suggest you read the forum guide https://social.technet.microsoft.com/Forums/exchange/en-US/77c07b69-eea6-43ab-9225-4b384cecfc9d/exchange-development-forum-guide-read-before-posting?forum=exchangesvrdevelopment and the update your question with more relevant information and detail what you have tried based on the research you have done etc.

    Cheers
    Glen

    Tuesday, November 14, 2017 3:39 AM
  • sorry this is my first question

    i have a service account with email, and i want to check one folder for new messages
    if i can read the subject and the body text in PowerShell, then i can export body text to txt file
    when its done, delete the email, and check for new messages

    (i use exchange 2013)
    connect to exchange i PowerShell:

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://exchange-server/PowerShell/ -Authentication Kerberos -Credential $xxxx
    Import-PSSession $Session

    Tuesday, November 14, 2017 6:47 AM
  • You won't be able to do this from Remote PowerShell You can use EWS on Exchange 2013 eg to get started i would suggest reading 

    https://blogs.technet.microsoft.com/heyscriptingguy/2011/12/02/learn-to-use-the-exchange-web-services-with-powershell/

    http://gsexdev.blogspot.com.au/2012/01/ews-managed-api-and-powershell-how-to.html  

    a really basic example of enumerating through all the Items in a Folder

    https://github.com/gscales/Powershell-Scripts/blob/master/EnumerateItemsInFolder.ps1

    (if you google EWS and Powershell other people have posted lots of examples and different explanations if none of these make sense) 

    Wednesday, November 15, 2017 5:54 AM
  • You can also cerate a sheduled Task, that exports emails with the subject to a pst File. Then you import them into that Mailbox that you monitor and delete them afterwards.

    $subjectstring = Read-Host 'Please enter the Subject String'

    foreach ($mbx in (Get-Mailbox | Where {$_.ExchangeVersion.ExchangeBuild.Major -eq 14})) {New-MailboxExportRequest -Mailbox $mbx -ContentFilter "subject -like '$subjectstring'"} -FilePath "\\export-server\mailboxexport\$($mbx.Alias).pst"}

    Wednesday, November 15, 2017 8:34 AM