cavac has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, i need a little bit of advice.

In 'my' production plant i have a separate network (very limited outside access). Many programs and some of the RAID controllers send status messages (for example "disk failed on server X in array y") via Email.

Our current mailserver is currently dying, so in need to replace it. Of course, i could just set up a new linux box and stuff one of the standard mailserver on it (done that enough times). But, what i actually want to do is set up a Perl based server that stuffs everything into my database. From there, my existing software could just update the computer status database and bugtracker.

Most of it is quite clear to me and i found a number of modules to play SMTP server and parse the mails. But i'm just not sure which ones i should use. Haven't done that for a decade or so.

So i'm hereby asking you for your advice which modules you recommend to use for running a basic SMTP server and to parse the Emails. The mails are all plaintext, i'm mostly need sender, reciever, title and some keywords (=regex) from the body anyway. No SPAM check, no validation.

I'd probably just go and random-test some modules till i find what i like - but my hardware guy assures me the old mail server won't survive next weekend (he's usually right about such things), so i'm in a tiny little bit of a hurry.

You don't need to post example code or anything, a pointer in the right direction will be very much appreciated.

Thank you in advance!

BREW /very/strong/coffee HTTP/1.1
Host: goodmorning.example.com

418 I'm a teapot

Replies are listed 'Best First'.
Re: SMTP Server - which module
by Corion (Patriarch) on Dec 13, 2011 at 10:15 UTC

    I have used neither and I would really look towards exim4 or one of the other mail frontends to do all the queueing etc., especially if this is going to be a hurried replacement.

    Later on, you can still implement forwarding rules to a (local) different mailserver written in Perl.

    I'd look at qpsmtpd (old, but likely still usable), and AnyEvent::SMTP, but both parse the complete mail before handing it off to you.

    Alternatively, as long as you can assume that all incoming mail will be well-behaved, maybe just faking the SMTP protocol from a plain socket is Just Enough - but I'd still look towards a proven mail server first and gradually replace it by forwarding selected mails to other servers.

      Yeah, i can pretty much assume the mail senders are well behaved. Except that i have to make sure the mailserver is in a catch-all configuration (doesn't care about sender and reciever beeing "known" to it).

      Also, the volume is pretty small, on the order of 100-300 mails per day.

      Later on, you can still implement...

      No i can't. From experience i just know that in my company any temporary setup that actually works stays the temporary setup until it just has to be replaced. That's how i inherited the old mail server in the first place. So i want to get it more or less right from the beginning (minor and major bugfixes on the other hand are much easier to implement).

      The problem is that my production plant pretty much runs 24/7. So unless something actually breaks, it's hard to get a time window to replace it. The old hardware is actually breaking (finally!) and i got an additional time window from 27.12 to 30.12. That opportunity wont come again any time soon...

      BREW /very/strong/coffee HTTP/1.1
      Host: goodmorning.example.com
      
      418 I'm a teapot

        If it is only a small volume, I would especially stay with a proven and implemented solution for the MTA instead of rolling my own in a week or two. If your clients are well-behaved, they might queue the status mails themselves and retry after some time so you get a chance to fix your code.

        Consider that you can set up the MTA to forward all mail to a Perl script anyway through a .forward file. I would avoid the risk of introducing an unproven component. The mailserver handles queueing and the complete protocol for you - why put that hassle on yourself if the usage is only 300 mails per day?

Re: SMTP Server - which module
by moritz (Cardinal) on Dec 13, 2011 at 10:46 UTC

    All modern mail servers allow some configuration to handle incoming mails to other processes, for purposes like spam filtering.

    So you could hijack that mechanism to write a custom "spam filter" that enters all the incoming emails into a database, and mark the all as spam, so that the mail server doesn't deliver them (unless you actually do want them delivered).

    I don't have any first hand experience with it, but I'd expect the battle proven mail servers to be more robust than the SMTP server modules you'll find on CPAN. (Of course that might do them great injustice, but I know that exim works well in the real world).

Re: SMTP Server - which module
by tobyink (Canon) on Dec 13, 2011 at 10:41 UTC

    I'd go with Postfix (non-Perl). Postfix (and most other decent SMTP servers I'm sure) can be easily configured to pipe incoming messages to a script. That can be your Perl.