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

Dear Monks,
I am not an expert in email coding, so please answer all my questions with tolerance :)
When I use email related perl modules, do I need to care about operation systems?
Do I need to think about whether or not I have an email server in my system?

I create and test my perl/cgi based web application on my Windows laptop and then port it to the external web host, like I guess many do. So I would prefer to have an email module which:

1) works on witdows, unix and linux platforms without thinking about email server, etc.

2) since I want an easy way of transfering my application from my laptop to the webhost I would prefer to use the module that can be put to my local lib together with all my subs.

If possible, could you suggest such module please.

Replies are listed 'Best First'.
Re: Questions about sending e-mails
by Corion (Pope) on Mar 19, 2009 at 17:35 UTC

    What makes you think the answers you got to Sending emails in perl/cgi environment are inapplicable to the situation you describe now? Did you try any of the suggestions? How did they fail for you?

Re: Questions about sending e-mails
by weismat (Friar) on Mar 19, 2009 at 17:35 UTC
    Perl is platform-independent.
    I guess you will not run your own SMTP server. Thus everything depends a bit on the provider of the SMTP server. MIME::Lite can do everything if you are happy with simple smtp. If you need SSL (like yahoo/google), Net::SMTP::SSL is your friend.
    my $msg=MIME::Lite->new(From=>$user, To=>join(",", @to_address), Subject=>$0, Data=>$data); my $smtp = Net::SMTP::SSL->new('xxx', Debug=>1, Timeout=>20, Port=>4 +65); $smtp->auth($user, $password) or die "Error message: $smtp->message" +; $status=$smtp->mail(); $status=$smtp->to(@to_address); $status=$smtp->data(); my $msgString=$msg->as_string; $status=$smtp->datasend($msgString); $status=$smtp->dataend(); $status=$smtp->quit();
    is a little example...
Re: Questions about sending e-mails
by sundialsvc4 (Abbot) on Mar 19, 2009 at 17:38 UTC

    Generally, e-mail is not the way that such things are done.

    Instead, you use tools such as rsync (using sftp or ftp or maybe WebDAV as the "transport") to move the files to the target location.

    In addition, since some amount of “installation” is necessary once the files have been moved, you must prepare that installation-file and probably log-on to the target server, using something like ssh, to execute the installation program and thus complete the installation.

    What you should do next is to ... "Google it." Read about how website installation is done, in-general. There's a huge amount of information out there. At first, it actually matters not-so-much if the information that you discover is specifically concerned with Perl. Discover what needs to be done, and discover the various ways that people have suggested for doing it.

Re: Questions about sending e-mails
by zentara (Archbishop) on Mar 19, 2009 at 17:41 UTC
Re: Questions about sending e-mails
by ig (Vicar) on Mar 19, 2009 at 18:10 UTC
    When I use email related perl modules, do I need to care about operation systems?

    There are differences between operating systems and these may affect you, depending on what you are doing and how you do it. You can read perlport for some initial guidance on portability and you should also read the platform specific documentation for your platforms of interest and release of perl. You can find the former from perl. The latter depends on your release - review your documentation to find it.

    Many of the email related modules are quite independent of platform but not all of them. Even if the modules are platform independent your code may not be. It is best to be careful and well informed about this issue if you want to write portable code. You may want to use only pure Perl modules that don't execute other programs on your system. Otherwise, and no matter what you do, you will have to test your application at some point. Plan thorough tests, test early and test often. Don't do all your development on one platform before testing on your alternate platforms.

    Do I need to think about whether or not I have an email server in my system?

    If you want to exchange email with other systems (you probably do) then you will have to think about mail servers. Some perl modules may try to access local mail related software (e.g. sendmail on *nix platforms) or other resources that differ from platform to platform (e.g. mailboxes). You will have to consider the availability of mail servers, how you will use them and how they are configured to support your application. You will likely want some mail server to relay messages for you and configuration of the mail server will probably be necessary to allow this. You will also have to decide what you will do if a mail server is not available at the time you wish to access it. A local mail server may be more available than a remote one. In many cases I have installed a local mail server for this reason and to let the local mail server handle queueing and routing of messages.

    I create and test my perl/cgi based web application on my Windows laptop and then port it to the external web host, like I guess many do. So I would prefer to have an email module which:

    1) works on windows, unix and linux platforms without thinking about email server, etc.

    When you stop thinking, your risk of unpleasant surprises increases dramatically.

    2) since I want an easy way of transfering my application from my laptop to the webhost I would prefer to use the module that can be put to my local lib together with all my subs.

    I don't understand what you are saying here. Sorry...

      Thanks a lot for your detailed response.

      /* since I want an easy way of transfering my application from my laptop to the webhost I would prefer to use the module that can be put to my local lib together with all my subs. */

      I mean I would prefer to place the module to my local application lib, not to perl/lib so that I could upload it as it is to the webhost.

      /* If you want to exchange email with other systems (you probably do) */

      all I need to do with emails in my application is to send a confirmation message to a given address. I do not need attachements.

        You can install any module (or at least the vast majority, I suppose there might be some with hard-coded path nonsense) anywhere you like.

        Installation is often more than just copying files. Some modules check for dependencies, compile and link code and configure themselves at installation. If you just copy the installed files you skip all these steps. If you are moving to a different platform this is more likely to be a problem.

        You can gain some insight into what the issues might be for a particular module by looking at how it is built and installed. If all that is done is copy .pm files into place, then you can just copy the files yourself. If more is done you will have to think carefully about the implications of skipping those steps when you copy the files yourself.

        What goes in the message is one thing. How you deliver it is another. If the body of the message is plain text, preparing it is easy. You still need to send it, either to a local or remote mail server, unless you are writing it directly to a local mailbox. There are perl modules that deliver via SMTP protocol without use of an external program.

        I have used Net::SMTP for simple cases in the past but there are many others. A search of CPAN for smtp yields many results.

Re: Questions about sending e-mails
by pileofrogs (Priest) on Mar 19, 2009 at 18:58 UTC

    If you're considering a web form that sends email, please think twice. Unless you do it right, you can open a gateway to spammers. I'm a sysadmin at a community college, and I've wound up blocking all outbound SMTP except to a few sites because students and instructors both write bad CGI+email apps which get used by spammers. Once that happens, your IP address gets added to spammer black-lists and routers start dropping your traffic until you beg the black-list people to take your name off. I'm not kidding.

    Unless you're well versed in writing secure apps, please do not write a web form that sends email.

    The documents at http://www.owasp.org/index.php/Category:OWASP_Project#Release_Quality_Projects are good reading.

    Good luck!

    --Pileofrogs

      pileofrogs++

      I used to administer a shared web server and before I was through, I was writing perl code that identified broken form mail programs, so that I could contact our customers and have them upgrade. My most common upgrade suggestion was to use NMS formmail. If you have to use an email script, that's the one I suggest. It was written by the London Perl Mongers and it works.

      d
      I am going to do something like
      my $msg = MIME::Lite->new( ##From =>'me@myhost.com', To =>xxx@xxx.com', ##Cc =>'some@other.com, some@more.com', Subject =>'Helloooooo, nurse!', Data =>"How's it goin', eh?" ); $msg->send; # send via default
      Just to send message to xxx@xxx.com
      Is it still unsecure?

        Are you actually going to use hard-coded values like in your example? If so, it probably is OK. If not, your example isn't very helpful.

        How do you take info from the web form and turn it into an email?

        --Pileofrogs