evolution
Goto Top

POP3 Postfach mittels Powershell löschen

Guten Morgen,

gibt es eine Möglichkeit mittels PowerShell auf ein POP3 Postfach mit TSL/SSL 955 zuzugreifen und komplett zu löschen?

Danke..

Content-Key: 358921

Url: https://administrator.de/contentid/358921

Printed on: April 19, 2024 at 20:04 o'clock

Mitglied: 134998
134998 Dec 21, 2017 updated at 11:11:51 (UTC)
Goto Top
Have a look at:
E-Mail Client für Kommandozeile
https://www.cyberciti.biz/tips/remove-or-delete-all-emails-message-from- ...
Or get a .NET Library like this one
https://www.limilabs.com/mail/download
And use it inside powershell with Add-Type.

Best regards
Tom
Member: evolution
evolution Dec 21, 2017 at 11:31:46 (UTC)
Goto Top
Member: colinardo
colinardo Dec 22, 2017 updated at 10:31:18 (UTC)
Goto Top
Servus @evolution ,
und wenn du eine reine Powershell-Lösung ohne Drittanbieter-DLLs bevorzugst geht das auch :
(Variablen im Kopf anpassen).
Das Skript löscht alle Mails in der Mailbox.
# POP HOST
$pop_host = "pop.gmail.com"  
# POP SSL PORT
$pop_port = 995
# POP USERNAME
$pop_username = "user@gmail.com"  
# POP PASSWORD
$pop_password = 'GEHEIM'  


function Get-Response([string]$command){
    try{
        if ($command -ne ''){  
            if ($client.Connected){
                $command = $command + "`r`n"  
                $bytes = [System.Text.ASCIIEncoding]::ASCII.GetBytes($command)
                $ssl.Write($bytes,0,$bytes.length)
            }else{
                throw "TCP CONNECTION DISCONNECTED"  
            }
        }
        $ssl.Flush()
        $data = @()
        $sr = New-Object System.IO.StreamReader $ssl
        while ($sr.Peek() -gt -1){$data += $sr.ReadLine()}
        return $data
    }catch{
        throw $_.Exception.Message
    }
}


try{
    $client = New-Object System.Net.Sockets.TcpClient($pop_host,$pop_port)
    $ssl = New-Object System.Net.Security.SslStream($client.GetStream())
    $ssl.ReadTimeout = 20 * 1000
    $ssl.AuthenticateAsClient($pop_host)
    Get-Response ""  
    Get-Response "USER $pop_username"  
    Get-Response "PASS $pop_password"  
    Get-Response "LIST" | ?{$_ -match '^(\d+) \d+'} | %{  
        Get-Response "DELE $($matches[1])"  
    }
    Get-Response "QUIT"  

}catch{
    write-host $_.Exception.Message
}finally{
    $ssl.close()
    $ssl.Dispose()
    $client.Close()
    $client.Dispose()
}
Frohes Fest
Grüße Uwe