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

One of the most useful things to do on a real world application is to get it to send email notifications. I have had a look through the CPAN modules for email and there doesn't seem to be any one particular module that caters for all situations.

Does anybody know if there is anything like an EMailD and EMailI module. Like DBD and DBI which allow database drivers. Instead I'm thinking Email Drivers!

Why? I do low-end web development on windows and Linux systems. Windows has exchange server, CDO, CDONTS, MAPI etc, Linux has sendmail, SMTP ...

I would like to be able to use all of these without having to change more than a singe driver name.

I would like to even be able to use two different drivers concurrently on the same platform in the same program. eg. one driver could use Mail::Sendmail and another Net::SMTP

I believe this would make the code a lot more transportable and reusable.

The code to use the email modules would look something like.

use EMailI; my $driver = "emaili::DriverName"; my $rc = EMailI->send($driver, USER => "user", PASSWORD => "password", HOST => "mydomain.com", SUBJECT => "test message", MESSAGE => "this is a test")

Any pointer or suggestions?

Replies are listed 'Best First'.
Re: Unified Perl Email. Has it been done?
by tachyon (Chancellor) on Mar 19, 2004 at 13:47 UTC

    On the sending side Mime::Lite deals with Sendmail or Net::SMTP on unix and will pick what works automagically. Because Net::SMTP will work on Win32 code should port to Win32 seamlessly. On the receive side Mail::Box is an attempt to provide a common access API to different mail box formats.

    M$ change their APIs so often you will never have smooth sailing when you try to deal with their stuff. See Microsoft versus GM for an amusing viewpoint on this. Especially the second last point :-)

    cheers

    tachyon

Re: Unified Perl Email. Has it been done? (yes)
by grinder (Bishop) on Mar 19, 2004 at 13:55 UTC

    Assuming you have an SMTP server lying around, then the simplest and most unified way of sending mail is to use Mail::Sendmail. It does not require sendmail, and is a pure Perl module.

    The trouble with Net::SMTP is that it talks raw SMTP. If the remote server is not responding you have to deal with retrying yourself, whether this be through secondary MXes (a dying breed, thanks to spam) or exponential backoff. These tasks are much better handled by an SMTP server. Use it.

    The examples bundled with Mail::Sendmail show a few recipes for generating MIME-encoded mail, which can save you from having to install MIME-tools (although that's a very handy module to have in its own right).

    Thanks to the power of RFC documents, there is a standard method for sending e-mail. Hence there is no need for multiple drivers (thank Baud).

      Yeah, maybe my email requirements are minimal (I don't need attachments and the like), but I use Mail::Sendmail extensively on both Unix and Windows, and basically install it at every site I work at.
Re: Unified Perl Email. Has it been done?
by Abigail-II (Bishop) on Mar 19, 2004 at 13:50 UTC
    One of the most useful things to do on a real world application is to get it to send email notifications.
    Hmmm, I always took the saying applications evolve until they can send email was meant to be negative.
    Does anybody know if there is anything like an EMailD and EMailI module. Like DBD and DBI which allow database drivers. Instead I'm thinking Email Drivers!
    Have you checked Mail::Send? I prefer to use /bin/mail or /bin/mailx myself though.

    Abigail

Re: Unified Perl Email. Has it been done?
by dragonchild (Archbishop) on Mar 19, 2004 at 13:48 UTC
    It doesn't exist.

    If you need it, go ahead and write it. If you want to have a similar to interface to the DBI/DBD:: modules, we can definitely help you out there. Some of us might even be interested in helping out.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Re: Unified Perl Email. Has it been done?
by flyingmoose (Priest) on Mar 19, 2004 at 15:30 UTC
    Windows has exchange server, CDO, CDONTS, MAPI etc, Linux has sendmail, SMTP ...
    You are confused here, or at least on a module-overuse binge :)

    We don't need a unified mail interface at all. Linux doesn't "have" SMTP. SMTP is "Simple Mail Transfer Protocol" and is the protocol that all mail (even on Windows), wants it escapes the evils of MS Outlook and the like, speaks with. If you want to send mail, use a pure perl module that speaks SMTP protocol. Even exchange boxes usually accept SMTP input from internal machines, ex: mailhost.yourcompany.com

Re: Unified Perl Email. Has it been done?
by chip (Curate) on Mar 19, 2004 at 17:06 UTC
    The whole point of SMTP is to be the universal layer, and no matter your mail environment, you're likely to find an SMTP gateway for it. I'd just use a module that knows SMTP and carry on.

        -- Chip Salzenberg, Free-Floating Agent of Chaos