Чтобы связать с почтовым сервером через командную строку, вы можете использовать либо telnet
, либо openssl
.
Вы можете подключиться к вашему серверу поп с помощью следующей команды (я взял Gmail в качестве примера Вы должны будете искать ваш электронный адрес хоста pop3 и розетку..):
openssl s_client -connect pop.gmail.com:995 -quiet
Как эта команда является взаимозависимой, она будет запрашивать имя пользователя, пароль и последовательность команд.
expect
- это инструмент, который может автоматизировать взаимодействие с интерактивными командами. Основной синтаксис следующий: expect "somestring" action
-> Если программа, которую мы контролируем, отображает «somestring», мы выполняем действие.
Вот скрипт, который будет удалять все сообщения, присутствующие на ваш адрес электронной почты:
#!/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
Вы, возможно, потребуется изменить настройки учетной записи электронной почты, чтобы позволить использование внешних программ
что ваша электронная почта адрес хоста? В зависимости от стандартов безопасности, которые у вас есть, вы можете использовать 'telnet' или' openssl' для удаления своих сообщений – Aserre
Я использую poczta.o2.pl , насколько я знаю, это работает только с openssl –