I need a very simple daemon script that receives all emails to a domain name and just forwards them to a script. I know there's software like exim, qmail or others to do this, but I do not want to install big software that eats performance in the host.

I have the MX record of the domain pointing to the host; now I need some daemon listening on port 25 and answering correctly to the mail standard communications (HELO and that stuff), and then handing the mail to a script.

How can I do that?

Edit: the domain.com will JUST be incoming, I don't need that domain to have POP accounts, or send emails; the domain will just receive emails addressed to *@domain.com, and I would like all of them to be redirected to a script.

I would like it in C or Perl if possible


The Python standard library include the smtpd module which implements the smtp server protocol. You should be able to do what you want with a few lines of python.

Here is some sample code to start from:

import smtpd
import asyncore

class CustomSMTPServer(smtpd.SMTPServer):

    def process_message(self, peer, mailfrom, rcpttos, data):
        print 'Receiving message from:', peer
        print 'Message addressed from:', mailfrom
        print 'Message addressed to  :', rcpttos
        print 'Message length        :', len(data)

server = CustomSMTPServer(('', 25), None)

  • Thank you but I do not know python :( – user6686 Apr 19 '11 at 5:02
  • If you know C and Perl, Python should be the easiest language to learn. Probably there is only one line missing to finish this script. How should the mail be redirected to your script ? What to do with the recipients and the body of the message ? – philfr Apr 19 '11 at 7:59

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.