Tksoft Inc.
Papinkatu 19
06100, Porvoo
Tel.+358 40 570-9900
Tel.+358 19 524-4030
Fax +358 19 524-3115


NTsendmail is a free Perl module (GNU License) to enable sending mail from NT servers. NTsendmail was specifically designed to enable script writers to use their UNIX CGIs on NT servers. NTsendmail also works on UNIX / Linux

PROBLEM: You have a UNIX CGI written in Perl which sends mail by opening a pipe to sendmail and feeding it a mail message.


#! /usr/bin/perl -w
$sendmail = "/usr/lib/sendmail";
open (MAIL, "| $sendmail -t -f \'tester\@1testdomain.com\'") || die ("Opening pipe failed."); 
print MAIL "From: tester\@1testdomain.com\r\n";
print MAIL "To: tester\@1testdomain.com\r\n";
print MAIL "Subject: Message from NTsendmail\r\n";
print MAIL "Hi there. It's a wonderful day outside, isn't it?\r\n";
close (MAIL);
exit 0;
You soon realize that NT doesn't have sendmail, or any other means of sending mail from the command line.


  • Install NTsendmail.pm, the NTsendmail object module in your perl libraries directory. Typically "c:\\perl\lib\." You can also install NTsendmail.pm in the same directory with your cgi/application.
  • Add into your CGI's environment a variable called "NTsendmail" and set its value to the name of a mail server which accepts relaying from your NT server. This can be the machine you are on, or another machine. You do this by adding the following line to your CGI *:
    $ENV{"NTsendmail"} = "smtp.mydomain.com";
  • Add the following line to the beginning of your perl script:
    "use NTsendmail;"
  • Send mail with the following syntax:
    $mail = new NTsendmail;
    $mail->send($sender, $recipient, $subject, $message);

    * %ENV is the environment variable hash in Perl.

  • SECURITY, CONFORMITY: You might have noticed that NTsendmail calls the local mailserver, or another mailserver which accepts mail from your machine. This is done to guarantee that all mail handling, caching, etc. is done according to the same rules as all your other mail.

    This method of specifying a mailserver also allows you to run Perl CGIs on a server without a mailserver, using another machine's mailserver instead. By utilizing a mailserver behind a firewall, this feature can be used to complement your company's security policies for mail.

    NTsendmail is a true plug and play solution, instead of requiring complex configurations of its own.

    You plug it in and use it. That's all there is to it.

    REQUIREMENTS: You must have Perl installed on your NT system. (Tested on Perl 5. Perl 4 might work.) Requires the Socket module to be installed. If you are not sure whether you have it, look for a file called socket.pm in the Perl lib directory. (Usually, c:\\perl\lib\socket.pm).

    NTsendmail makes multiple attempts to connect to a server if an error occurs during a connection. Default number of attempts is 3. You can change the number of attempts with the environment variable NTsendmail_max_tries.
    E.g. $ENV{"NTsendmail_max_tries"} = 5
    will set the number of attempts to 5.

    If you define $ENV{"NTsendmail_debug"} in your script, you will get verbose error messages and the body of the emails sent also contains the number of attempts made in the process.
    E.g. "Attempts: 1/3" if NTsendmail_max_tries is set to 3.

    GETTING NTSENDMAIL: NTsendmail is released as freeware under the GNU license. Please see https://www.ntsendmail.com/ for details on how to download.

    Here is the above mail sending script modified for use with NTsendmail. Debugging has been enabled to show you the syntax.

    #! /usr/bin/perl -w
    use NTsendmail;
    $ENV{"NTsendmail"} = "smtp.mydomain.com";
    my $mail = new NTsendmail;
    my $from = "tester\@1testhost.com";
    my $to = "test\@1testhost.com";
    my $subject = "Message from NTsendmail";
    my $message = "Hi tk. It's a wonderful day outside, isn't it?";
    $mail->send($from, $to, $subject, $message);
    exit 0;

    This document and NTsendmail are
    Copyright 1997-2006 Troy Korjuslommi All Rights Reserved.