0

I need to forward *@domain.com to a script.

I know the EXIM way and the PROCMAIL way.

Is there a lighter way? Any experiences? Which one is the fastest if I JUST WANT it to delivery emails to script? (no pop accounts, nothing else)

(I knew qmail but I don't want to install "big" software that eats too many resources on the server).

naiad
  • 201
  • 2
  • 7
  • 1
    Why not just have your MTA run the script, and forgo the MDA altogether? – Ignacio Vazquez-Abrams Apr 15 '11 at 14:22
  • I just noticed you're scrambling things here. Procmail is an MDA (delivery agent). Exim is an MTA (transfer agent). You don't need an MDA, you just need the MTA. Your script is going to be the delivery agent. – Caleb Apr 15 '11 at 15:00
  • Updated question with MTA in the title, since you don't need an MDA, your question is about lightweight MTAs. – Caleb Apr 15 '11 at 15:48
  • BTW, if you search ServerFault or the Unix-SE site for "lightweight mta" you will get quite a number of people working on similar problems. – Caleb Apr 16 '11 at 15:34
  • 1
    Maybe it's worth considering you have the wrong technology altogether! If you are going to be receiving so many emails that are to be automatically processed by a script that it uses up server resources, perhaps you should reconsidering using email at all and just write an API for your two things to talk together. What is in these emails? Maybe we can suggest something else entirely. – Caleb Apr 16 '11 at 15:53
  • It has to be email system. People send attachments by email and I have to handle them. It's the way the customer needs. – naiad Apr 17 '11 at 12:17

4 Answers4

3

What you are asking is really about MTAs (Mail Transfer Agents) rather than MDAs (Mail Delivery Agents). Your question includes comments about both (Procmail is an MDA, exim is an MTA).

In your case you are going to dispose of any MDA by just "delivering" to your script. In exim an alias like username: |/path/to/script is enough to get that part done with no fancy internal routing or MDA needed.

As for the MTA, Exim is actually pretty light weight. It doesn't provide pop accounts or anything else, it just handles the chat with other mail servers to accept messages, then passes them off to somebody (Usually an MDA or other mail servers).

Don't make life more complicated for yourself down the road by trying to make a non-standard setup, short circuit normal protections like the validation that MTA's run on incoming mail, etc. Just wire the right parts together. Using a pipe-alias in exim as above is a dead simple way to route mail to a script and still behave properly as an MTA.

Caleb
  • 11,813
  • 4
  • 36
  • 49
  • I don't need pop accounts, nor SMTP ... nothing but listening to emails from *@domain.com and redirect everything to a PHP script. That domain.com will not have accounts, or need to send anything. Just listening ! any super light mda ? – naiad Apr 16 '11 at 02:07
  • @user75317 Please let us help define your problem, not just answer the one you have in your head. YOu DO need SMTP, that is the protocol that mail servers use to talk to each other and you need to talk in order to "listen to emails" that come in. I realize you don't need pop accounts, exim does NOT PROVIDE pop. That would take some other people of software and nobody here is recommending anything that provides it. – Caleb Apr 16 '11 at 07:46
  • I know there's software to accomplish this. But I've been testing exim and qmail and they eat too many resources. I need the host in a high level performance, so I can not install software happily. So, I would need a way to have a simple daemon listening to mail protocol and receiving all emails from a domain name (*@mydomain.com), and forward all the mail to a script. netcat would not answer to standard mail protocol communications. AFAIK, I need a script listening and handling the HELO, RCPT TO, etc ... from external SMTP sending emails to my host. – naiad Apr 16 '11 at 17:27
1

Do you really want the script to just run, regardless of what is passed to it? Or do you want proper SMTP handling?

The lightest way might be to use something like Python's Twisted library listening for SMTP or a node.js SMTP server script, and have it fire of a script on each message required. That way you get full multi-threading, without much of anything else in the way.

I would say though that Exim and the others like it will be more than fast enough for 99% of uses.

Ewan Leith
  • 1,705
  • 8
  • 7
  • I'm not looking just to be fast, but to be the lighter way. I do not want to compromise performance of the host. I do not need POP accounts, SMTP ... nothing but to listen to *@domain.com forwarding all of that to a PHP script. – naiad Apr 16 '11 at 02:05
  • Firing up a PHP shell for each email received is going to have significantly larger impact on resources than exim or anything else. PHP is not a lightweight solution, the PHP processor is a significant hit. I think you need to re-frame your problem and possibly redesign your solution. Exim can send and receive millions of emails per day. – Ewan Leith Apr 18 '11 at 14:48
0

If you can spare port 25 on a unique IP what about using netcat to listen on port 25 ? That's truly zero load and install. A wrapper script to restart it after a reboot/fail should be easy too.

Jonathan Ross
  • 2,183
  • 11
  • 14
  • Sounds cool !!! But, do you know any script to start with ? I mean, I'm not going to start from scratch and RFC documents to see how to listen properly to mail from other servers :P – naiad Apr 16 '11 at 02:06
  • I found this one : http://sourceforge.net/projects/fdm/ – naiad Apr 16 '11 at 04:02
  • It's really easy `netcat -l 25 > /tmp/filename`. Loads on examples on the web, one here: `http://h.ackack.net/cheat-sheets/netcat` – Jonathan Ross Apr 16 '11 at 05:27
  • when somebody tries to send an email it won't work ! I change the MX records to the IP of the host, and then what ? the script needs to hear from a standard mail connection protocol ... the HELO, and all stuff ... – naiad Apr 16 '11 at 15:20
  • Netcat will basically grab anything sent to port 25 ... anything ! – Jonathan Ross Apr 16 '11 at 16:01
  • yes, but ... I'm Gmail sending an email to aaaa@domain.com ... I will tell "HELLO domain.com" ... and netcat will not answer !, so Gmail will not send the email ! I don't need just a listener, but a script receiving emails! – naiad Apr 17 '11 at 11:21
  • Aah, ok, sorry. Useful for some scenarios though. – Jonathan Ross Apr 17 '11 at 11:27
  • This is the proof ... what Gmail answers when try to send an email, and the host is just "using netcat". Technical details of permanent failure: Google tried to deliver your message, but it was rejected by the recipient domain. We recommend contacting the other email provider for further information about the cause of this error. The error that the other server returned was: 550 550 #5.1.0 Address rejected aaaa@domain.com (state 14). (obviously, replace domain.com with the real domain ;) – naiad Apr 17 '11 at 11:52
  • Other than writing a few lines in a script to exchange the 'ehlo' and ask for 'rcpt' details then it will just receive data. – Jonathan Ross Apr 17 '11 at 12:11
  • That's what i do not know :) – naiad Apr 17 '11 at 12:16
  • Here's a start: http://www.foureleven.org/pub/nc/#SMTP – Jonathan Ross Apr 17 '11 at 12:39
  • http://www.linuxquestions.org/questions/linux-software-2/how-to-automate-smtp-emails-using-netcat-not-telnet-692505/ and http://nerds-central.blogspot.com/2007/03/sending-emails-using-netcat-with.html – Jonathan Ross Apr 17 '11 at 12:40
  • Sorry for all the links: http://www.allgoodbits.org/articles/view/17 – Jonathan Ross Apr 17 '11 at 12:47
  • Last link is probably the best: http://docstore.mik.ua/orelly/networking_2ndEd/snmp/ch12_06.htm – Jonathan Ross Apr 17 '11 at 13:16
  • Happy to help :-) – Jonathan Ross Apr 17 '11 at 14:40
  • I've been checking your URL's ... they give info to use netcat as a SMTP to SEND emails, but I need to RECEIVE them ... :( I think i'm not explaining myself ... what i need is a DAEMON to listen properly to email standard communications to grab all emails ... i mean, a very super lightweight qmail to handle all emails in a domain name. just that ... :( – naiad Apr 17 '11 at 21:40
  • Yes, I realise but between them the links give you all the necessary information to easily reverse the process. It's a case of using something like the language `expect` to reverse this: `echo EHLO $USER@$HOSTNAME sleep 1 echo MAIL FROM: $USER@$HOSTNAME sleep 1 echo RCPT TO: $EMAIL_TO sleep 1 echo "DATA From: $USER@HOSTNAME To: $EMAIL_TO Subject: $EMAIL_SUBJECT $EMAIL_DATA" sleep1 echo '.' sleep 1 echo QUIT) | netcat mailserver.somewhere.org 25` It would be a ten line script. – Jonathan Ross Apr 18 '11 at 05:25
  • Something like this in reverse: http://forums.debian.net/viewtopic.php?f=8&t=17352 – Jonathan Ross Apr 18 '11 at 05:34
  • Here's a web server example. Good luck with it, that's all from me: `:;while [ $? -eq 0 ];do nc -vlp 81 -c'(r=read;e=echo;$r a b c;z=$r;while [ ${#z} -gt 2 ];do $r z;done;f=`$e $b|sed 's/[^a-z0-9_.-]//gi'`;h="HTTP/1.0";o="$h 200 OK\r\n";c="Content";if [ -z $f ];then($e $o;ls|(while $r n;do if [ -f "$n" ]; then $e "`ls -gh $n`";fi;done););elif [ -f $f ];then $e "$o$c-Type: `file -ib $f`\n$c-Length: `stat -c%s $f`";$e;cat $f;else $e -e "$h 404 Not Found\n\n404\n";fi)';done` – Jonathan Ross Apr 18 '11 at 06:09
0

If you just want to recieve E-Mails you can use a "server" like http://code.google.com/p/subethasmtp/ .

You can have a 1 file java program using this library that will accept all emails and execute some code for it. The problem with it is you will need to have java present on the machine.

  • Hmmm ... I can't install java in the server ... but thank you, I'm trying to find some similar project in Perl or C. – naiad Apr 17 '11 at 11:56