4

I have a mail account that receives and stores copies of receipts sent to customers making reservations.

As the account gets filled up over time, and as I have no interest in looking at the content and manually handle the mails, I need an automatic solution to log on and delete mails older than x days.

PHP scripting is not an option as my service provider do not allow script access to the mail server.

Any ideas for a (mail) service that can set up a rule to delete these automatically (without having me log in to their system)?

  • 2
    Most email clients have such a "auto delete old messages" feature. Can you or they just enable that feature on whatever client app they use to review their messages? – Basil Bourque Nov 28 '15 at 21:46
  • Have been in touch with them - they have no solution - have tried to convince them to upgrade their system but to no avail... – Morten Repsdorph Husfeldt Nov 29 '15 at 15:40
2

I could not place a script accessing the mails on my domain. However, it turns out that they only blocked localhost access - but not external host access. Therefore, my answer to the solution was, in the end, a php script.

Thought I would share it for those interested.
Never found a service that could help me though.

Script for auto deleting old mails:

<?php

$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);
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.