Um mit einem Mail-Server über die Befehlszeile abzufragen, können Sie entweder telnet
oder openssl
verwenden.
Sie können Ihren Pop-Server verbinden mit dem folgenden Befehl (ich habe gmail als Beispiel genommen Sie werden für Ihre E-Mail-Host Pop3-Adresse und Steckdose suchen..):
openssl s_client -connect pop.gmail.com:995 -quiet
Wie Dieser Befehl ist interaktiv und fragt nach einem Benutzernamen, einem Passwort und einer Reihe von Befehlen.
expect
ist ein Tool, das die Interaktion mit interaktiven Befehlen automatisieren kann. Die grundlegende Syntax lautet wie folgt: expect "somestring" action
-> Wenn das von uns überwachte Programm "somestring" anzeigt, führen wir die Aktion aus.
Hier ist ein Skript, das alle Nachrichten auf Ihrer E-Mail-Adresse vorhanden löschen würde:
#!/usr/bin/expect
#you can modify the timeout if the scrpit fails
set timeout 1
#our connection variables
set ip "pop.gmail.com"
set socket "995"
set user "user.name"
set pass "password"
#we set the address we want to remove mails from here. Escape special regex characters such as dots.
set target_address "mail\[email protected]\.com"
#we launch the subprocess we want to interact with
spawn openssl s_client -connect $ip:$socket -quiet
#if connection went all right, we try to login
expect -re ".OK.*" {send "user $user\r"}
expect -re ".OK.*" {send "pass $pass\r"}
#if login went alright, we try to count the messages on the server
#you will get the following output :
#+OK NB_MSG TOTAL_SIZE
expect -re ".OK.*" {send "stat\r"}
#if the stat command went allright ...
expect -re ".OK.*" {
#we extract the number of mail from the output of the stat command
set mail_count [lindex [split [lindex [split $expect_out(buffer) \n] 1] " "] 1]
#we iterate through every email...
for {set i 1} {$i <= $mail_count} {incr i 1} {
#we retrieve the header of the email
send "top $i 0\r"
#if the header contains "To: $target_address" (or "To: <$target_address>" or "To: Contact Name <$target_address>" ...)
#to filter according to the sender, change the regex to "\nFrom: ..."
expect -re "\nTo: \[^\n\]*$target_address" {
#we delete the email
send "dele $i\r"
}
}
}
expect default
Sie können Ihre E-Mail-Kontoeinstellungen ändern müssen, um die Verwendung von externen Programmen
, was Ihre E-Mail ermöglichen Adresse des Gastgebers? Abhängig von den Sicherheitsstandards, die es hat, können Sie entweder 'telnet' oder' openssl' verwenden, um Ihre E-Mails zu löschen. – Aserre
Ich benutze poczta.o2.pl soweit ich weiß funktioniert dies nur mit openssl –