We have exim4 set up on Debian as a smarthost to send mail via Google's mail servers. We use Google Apps for everything else, so this made sense. Problem is, the password for the smart host account was changed, causing exim to bounce the messages back and then freeze them. Now I have a large collection of unsent mail in /var/spool/exim4/[input|msglog].

I have tried running:

exim -d -M 1Mx6IS-0006bC-3h

but that causes the bounced message to be sent, not the original. I can see a copy of the original message in /var/spool/exim4/input/1Mx6IS-0006bC-3h-D under the line

------ This is a copy of the message, including all the headers. ------

...but I have not figured out a way to take this frozen bounced message, and convert it back to the original message so it can be retried.

Any ideas?



This is a python script that should do what you want. It is thoroughly untested, and is guarenteed not to work in all cases. If you don't know Python, then nevermind, it was a nice bit of practice for me.

import os
import smtplib
import email

mydir = os.open("/mydir")
server = smtplib.SMTP()

files = [mydir + "/" + f for f in os.listdir(mydir) if os.path.isfile(mydir + "/" + f)]

while files:
    f = files.pop()
    msg = email.message_from_file(open(f))
    body = msg.get_payload().split("------ This is a copy of the message, including all the headers. ------")[1].strip()    
    from_addr = msg["To"]
    to_addr = msg["X-Failed-Recipients"]
    print "Sending message to ", to_addr
    server.send(from_addr, to_addr, body)
    print "Message sent"
  • Thanks... that is actually what I ended up doing, but in BASH – Peter Sankauskas Oct 21 '09 at 16:04

Is this a final bounce? Or the one that says that another attempt to deliver will happen in some number of hours, if later, could it be that both messages are sent out, the original and bounce? Since both are in the queue, as I understand it from your question.

  • Yes it is a final bounce. Only a manual process of converting bounced message or extracting the original message from the bounce will work. – Peter Sankauskas Oct 13 '09 at 21:56

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.