Postfix: redelivering delivered mail

I set up a user in postfix with local mail delivery, but it turns out he wants to use the gmail interface. So I set an alias entry for him, and new mail for him goes to gmail now.

There are 100 or so messages delivered in his local Maildir directory. I'd like to send them on to his gmail account, but I don't see how to get postfix to redeliver delivered mail.

I suppose I could set up a pop server, get him to configure gmail to pop the mail, and then take it down again once he's done. Given the technical sophistication of the user, most alternate solutions are likely easier.

Is there a way to requeue these delivered messages?


Solution 1:

Once messages have worked through postfix there's no memory of them, meaning that the solution is the same as for re-sending messages in general, which is to use the Resent-To header.

You'd need to do it with a loop, and depending on the number probably rate-limit yourself to avoid issues with Gmail. Along these lines, adjust as necessary.

MDIR=/home/user/Maildir
[email protected]
for MF in ${MDIR}/cur/*
do
  cat ${MF} | sed "/^To:.*/a Resent-To: ${TOADDR}" | sendmail -t
  # Self-limit sending rate
  sleep 10
done