Get email using PowerShell

前端 未结 2 1510
你的背包
你的背包 2020-12-17 05:43

All I need is get email in PowerShell Script and see at its topic - with pop3 or imap, doesnt matter.
I tried to find solution, but all I found is either 3rd party .net

2条回答
  •  无人及你
    2020-12-17 05:56

    I used the suggestion of Falah Abu Hassan and it worked very well for my requirements for receiving mails via IMAP!

    How to get the IMAPX.DLL

    The Github Repository for imapx is found here: https://github.com/azanov/imapx

    Unfortunably you have to compile it yourself with "Visual Studio" to get the imapx.dll.

    Creation of an sample Powershell Script

    The Script and the DLL should be placed side and can integrated with this:

    $path = Split-path $script:MyInvocation.MyCommand.Path
    [Reflection.Assembly]::LoadFile(“$path\imapx.dll”)
    

    The following example script, inspired by the answer from Falah Abu Hassan worked very well for me:

    $path = Split-path $script:MyInvocation.MyCommand.Path
    
    [Reflection.Assembly]::LoadFile(“$path\imapx.dll”)
    
    ### Create a client object
    $client = New-Object ImapX.ImapClient
    
    $client.Behavior.MessageFetchMode = "Full"
    $client.Host = "Servername"
    $client.Port = 993
    $client.UseSsl = $true
    $client.IsDebug = $true
    $client.ValidateServerCertificate = $true
    $client.Connect()
    
    $user = "login@domain"
    $pass = 'password'
    
    
    $client.Login($user, $pass)
    
    $messages = $client.Folders.Inbox.Search("ALL", $client.Behavior.MessageFetchMode, 100)
    
    write-host "Count found: $($messages.count)"
    
    foreach($m in $messages){
        write-host "Processing Subject: $($m.Subject)"
    }
    

提交回复
热议问题