http://www.perlmonks.org?node_id=23299

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

I need to send an e-mail from a Perl script on an NT server (God, I hate them, but I don't have a freakin' choice). I can't use sendmail, so I went around the site looking for other resolutions to the problem. I tried using Mail::Mailer, didn't work. I tried using Mail::Internet, didn't work. I tried using Net::SMTP, it didn't work!!! I guess the server doesn't have those Modules installed.

Are there any other modules that I can use that are standard on NT or is there another way I could get around the problem or do I have a real problem?

Thanks.

Zenon Zabinski | zdog | zdog7@hotmail.com

Replies are listed 'Best First'.
(jcwren) Re: Sending mail on NT
by jcwren (Prior) on Jul 20, 2000 at 01:12 UTC
    Net::SMTP works fine on my NT servers. You can check if they're installed on your server by doing ths following:
    perl -e 'use Net::SMTP;'
    If you get an error to the effect that it can't find them, then they're indeed not installed. However, that shouldn't stop you from installing them. Since most NT systems really aren't setup for security (like Linux boxes), you could just hop on over to CPAN and fetch them. I think the Net::SMTP is a pure Perl module, so you shouldn't need a compiler to install it. You may have to grab a copy of make, nmake or dmake from somwhere however.

    Net::SMTP is not reliant on any underlying O/S programs, such as sendmail. It basically uses sockets to connect to the mail server. Which, incidently, could be your problem. You'll need the DNS entry or IP address of a mail server that supports SMTP, or it won't be able to send mail. If your business is running Exchange, it can easily be configured to support SMTP. A couple of settings in the admin program will set it up.

    Here's even some sample code to talk to the SMTP server (I've changed the address to 127.0.0.1, you'll need to use yours)
    #!/usr/local/bin/perl -w use strict; use Net::SMTP; my $globalMailServer = "127.0.0.1"; { sendmail ('you@address.com', # put real e-mail address + here 'My Name Goes Here', # put your real name here 'peon@company.com', # put dest e-mail address + here 'Leon The Peon', # put dest name here 'Your fired!', # subject 'This is some message text'); # message } sub sendmail { @_ == 6 or die "Improper number of arguments"; my ($fromemail, $fromname, $toemail, $toname, $subject, $message) += @_; my $smtp = 0; $smtp = Net::SMTP->new($globalMailServer) or die "Can't connect to + mail server named '$globalMailServer'\n"; $smtp->mail ($fromemail); $smtp->to ($toemail); $smtp->data (); $smtp->datasend ("To: $toname\n"); $smtp->datasend ("From: $fromname\n"); $smtp->datasend ("Subject: $subject\n"); $smtp->datasend ("\n"); $smtp->datasend ($message); $smtp->dataend (); $smtp->quit; }
    This subroutine is a direct extract from some code around here. I also just tested this code, so it should work for you, if you fix the mail server address.

    --Chris

    Update: I just noticed where you said you can't install modules. Is that because you're not permitted to, or because you don't believe you can since you're not a system administrator? If it's a case of the latter, CPAN modules can be installed into a users directory, as opposed to the system directories. If it's because they won't permit you, you can always hack the code out of Net::SMTP and include it in your script, or treat it as a module (doable, but not the wisest way.)

    e-mail jcwren
Re: Sending mail on NT
by infoninja (Friar) on Jul 20, 2000 at 00:56 UTC
    I've heard good things re: Blat!
    Disclaimer: I don't use Windows NT, so I can't vouch first-hand for Blat!
      Thanks for the input, but the problem is that it isn't my server so I wouldn't be able to install any programs on it, otherwise I would have installed the modules I needed.

      Zenon Zabinski | zdog | zdog7@hotmail.com

Re: Sending mail on NT
by lhoward (Vicar) on Jul 20, 2000 at 01:08 UTC
    You should be able to use Net::SMTP, you'll just have to send through a SMTP server on a remote host since NT does not provide sendmail service out-of-the-box. Alternatively you can set up a sendmail compliant main server on your NT host.
      Ummm, actually sendmail as such has very little to do with it. Since SMTP is a socket-based mail delivery protocol, he needs a socket service, either locally or remotely, that Net::SMTP can connect to, to provide SMTP service.

      To this end, MS Exchange, or several freeware clients can provide this service. Having sendmail is only relevant to programs that are trying to exec sendmail to send mail (and that's really an obsolete way to do it, these days).

      Someone mentioned Blat in a previous post. Blat does not provide SMTP service as socket provider, but will connect to a SMTP server and send the mail provided on the command line or parameters file. Several years ago I had written a Windows App that needed Blat to send mail, since there were no SMTP class libraries available. And you really don't want to write your own, since a number of the SMTP servers out there are somewhat quirky.

      --Chris

      e-mail jcwren
RE: Sending mail on NT
by Anonymous Monk on Jul 20, 2000 at 07:12 UTC
    I'm new at Perl, and i just figured this out today. Go to http://www.stalkerlab.ch/Smailers/Main.html and download their mail programs. just follow the directions they give you re: installing and where to put the mail.exe and mail.ini files. In your script add this: $mail_command= "echo <whatever you want as the body, minus the brackets> | mail -s \"Supply Request\" whoever@domain.com >process.log"; system($mail_command); Hope this helps. Kirk
Re: Sending mail on NT
by gaggio (Friar) on Jul 20, 2000 at 17:36 UTC
    You could also email without any third-party program like everybody here said.

    The only thing is that you need to have a connection to Internet, and the module Net::DNS installed...

    I am currently working on making a really nice package that will do that, and will probably post it on Perl Monks in a little while.

    Feel free to /msg me if you want more infos.