2

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

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
user6686
  • 121
  • 2

1 Answers1

2

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)
        return

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

asyncore.loop()
philfr
  • 1,056
  • 5
  • 11
  • Thank you but I do not know python :( – user6686 Apr 19 '11 at 05: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 07:59