May 16, 2005

How to send SMTP e-mail over SSL using Perl in the Windows environment, or
Install Notes for Net::SMTP::SSL and Net::SMTP::Multipart on Windows


(For the sake of convenience, I have made a zip file of all files listed
below [except ActivePerl] that you need to download. You can
download the zip file or get the files from the links below.)

---------
DOWNLOAD

0. Get/install Activeperl from:
http://www.activestate.com

1. Get OpenSSL for Windows, from:
http://gnuwin32.sourceforge.net/packages/openssl.htm
or
http://www.slproweb.com/products/Win32OpenSSL.html

2. Get the Perl IO::Socket::SSL module from
http://perl.apache.org/dist/win32-bin/ppms/x86/IO-Socket-SSL.tar.gz

3. Get Net::SMTP::SSL from:
http://search.cpan.org/~cwest/Net-SMTP-SSL-1.01/lib/Net/SMTP/SSL.pm

4. Get Net::SMTP::Multipart from:
http://search.cpan.org/~droberts/Net-SMTP-Multipart-1.5/Multipart.pm

5. Get NMake from:
http://download.microsoft.com/download/vc15/patch/1.52/w95/en-us/nmake15.exe

6. Get/Install Authen-SASL with:
   ppm install Authen-SASL
---------
INSTALLATION
(Assuming you have already installed Perl)

1. Just run the Windows installer for OpenSSL.
   Then, open a comand prompt and go to
   \openssl\perl\5.8\Net_SSLeay, and run the install.bat
   file to install Net::SSLeay.
2. The IO::Socket::SSL module is just an archived file.
   Unzip it into your Perl directory.  It has ./lib,
   ./html, etc. subfolders which will just have their
   contents copied into the same Perl subfolders.
3. Nmake is a self-extracting archive.  Create a folder
   named c:\nmake and extract it there.  You could extract
   it somewhere in your path, like c:\windows too.
4. Extract the Net::SMTP::SSL source and open a command
   prompt in its directory, then:
   perl Makefile.PL
   \nmake\nmake.exe
   \nmake\nmake.exe test
   \nmake\nmake.exe install
5. Extract the Net::SMTP::Multipart source and open a command
   prompt in its directory, then:
   perl Makefile.PL
   \nmake\nmake.exe
   \nmake\nmake.exe test
   \nmake\nmake.exe install

6. By default, Net::SMTP::Multipart does not use SSL.  To make
   it use SSL, just change line 26 of its code from:
   @ISA = qw(Net::SMTP);
   to
   @ISA = qw(Net::SMTP::SSL);
   
   But the module does two other things I don't like:
      a. When it names the attached file in the encoded e-mail,
         it names it with the entire path.
      b. It does not insert Content-type information in the
         encoded message, so email clients will try to open
         the base64-encoded data as text, which looks messy for
         the recipient.
   So, here is Dave Roberts' module, with a few modifications by me.
   Dave Roberts is the author of Net::SMTP::Multipart, not me.
   My changes are very trivial, and are there just to adjust
   how it works for my preferences.  He did all the heavy lifting.
   Download the modified Multipart.pm here.
   (note: right-click the above link, and select Save Link As in your browser)
   Move it to c:\perl\site\lib\net\smtp\
   (make a backup copy of the old one first, and
     you will need to replace the .txt filename
     with .pm too)

--------
TESTING

Create a test.pl file with the following code:
#!/usr/bin/perl
use Net::SMTP::SSL;
use Net::SMTP::Multipart;
print "Any errors?  Hope not!\n";

Test it with:
perl test.pl

If no errors are reported, you probably have Net::SMTP::SSL and
Net::SMTP::Multipart correctly installed in your Windows system.
I say probably because you haven't tried to send anything yet.

Here is some sample code for a complete test, that shows how to send a plain
text message, and a message with an attachment.
(note: right-click the above link, and select Save Link As in your browser)
www.000webhost.com