Below is a perlscript to do approximately what you asked. I found it
somewhere else on the web. Unfortunately I do not remember where, and I
have seen several similar. It is pretty basic anyway.
I have a database application that outputs pay stubs to a text file. I
then use another script to convert the text file to a pdf file. and this
script to e-mail the pdf file.
This uses no M$ tools and should port to any OS that Perl runs on.
I am not sure I understand your security reference. Any e-mail that goes
over the internet is pretty basically hanging out there for anyone to
see. You can encrypt it (The .pdf files I send are encrypted, but that
is not currently the norm. All you need is access to an SMTP server to
send e-mail, but that is pretty much all you ever need to send e-mail.
Sending via MAPI might be more secure, but only if the e-mail is
internal to your organization and though there are Perl MAPI modules,
MAPI is an M$ mail protocol, with its own idiosyncrasies and annoyances.
#!/usr/bin/Perl
use MIME::QuotedPrint;
use MIME::Base64;
use Mail::Sendmail 0.75; # doesn't work with v. 0.74!
$file = $ARGV[0] ;
$to = $ARGV[1] ;
$msg = $ARGV[2] ;
%mail = (
SMTP => 'mail.yourdomain.com',
from => '[EMAIL PROTECTED]',
to => "$to",
subject => "This is your e-mail subject",
);
$boundary = "====" . time() . "====";
$mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
open (F, $file) or die "Cannot read $file: $!";
binmode F; undef $/;
$mail{body} = encode_base64(<F>);
close F;
if ($msg ne "") {
open (F, $msg) or die "Cannot read $msg: $!";
binmode F; undef $/;
$message = encode_qp(<F>);
close F;
}
if ($msg eq "") {
$message = encode_qp( "file Attached: $file" );
}
$boundary = '--'.$boundary;
$mail{body} = <<END_OF_BODY;
$boundary
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
$message
$boundary
Content-Type: application/octet-stream; name="$file"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="$file"
$mail{body}
$boundary--
END_OF_BODY
sendmail(%mail) || print "Error: $Mail::Sendmail::error\n";
-----Original Message-----
From: Derek Brinson [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 02, 2003 6:42 PM
To: [EMAIL PROTECTED]
Subject: Output PERL to E-mail
I have a PERL installed on a WinIIS box. This script queries a (SQL)
database, makes a few minor manipulations to that data, then builds a
small paragraph of text, from there.
So, how do I send that text info to an e-mail address (gathered from
that same database)? How about several e-ddresses?
Surely there are several ways to do this. Isn't there a specific PERL
statement especially for this kind of thing? I *do* have FormMail
running on another machince (a UNIX/Apache Web Server) on the same
network. Would that be easier? More secure? How would I finish this task
that way? It is politically necessary avoid any M$ solutions, if
possible. Any other, better tacts/suggestions? Please fire away.
Yours,
-dB-
[EMAIL PROTECTED]
Web Master/Web Manager/Computer Consultant II
North Carolina Central University
712 Cecil Street Suite # 3014 (or 3010)
New Education Bldg. - NCCU Campus
Durham, NC 27707
Tele: (919) 530-7151 Fax: 530-5097