Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

share|improve this question
    
possible duplicate of Lightweight outgoing SMTP server –  Gilles Apr 17 '11 at 22:22
    
Do you have any code? –  matcheek Apr 18 '11 at 1:02
1  
No, i don't want outgoing , i want incoming !!! –  user6686 Apr 18 '11 at 5:38
add comment

1 Answer 1

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()
share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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