-2

I need to remove older emails automatically from webmail. How can I do it? Anyone have an idea?

Hal Abelson
  • 89
  • 1
  • 8

1 Answers1

0

You can use IMAP client libraries from different languages:

here are some examples:

I already used PHP to do this task.

<?php // Example from the first link

$del = new DateTime();
$del->modify('-1 month');

$mbox = imap_open("{imap.test.com:993/imap/ssl}INBOX", "username", "password")
 or die("can't connect: " . imap_last_error());

$MC = imap_check($mbox);

// Fetch an overview for all messages in INBOX
$result = imap_fetch_overview($mbox,"1:{$MC->Nmsgs}",0);
foreach ($result as $overview) {
    $date = $overview->date;
    $date = DateTime::createFromFormat('D, d M Y H:i:s O', $date); 

    if($date<$del) {
        imap_delete($mbox,$overview->msgno);
    }

}   
imap_expunge($mbox);
imap_close($mbox);
?>
Chocolord
  • 493
  • 3
  • 12