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? Commented Nov 28, 2015 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... Commented Nov 29, 2015 at 15:40

1 Answer 1


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:


$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) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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