Clarification of Answer by
webadept-ga
on
12 Sep 2003 02:14 PDT
Hi,
this setup using Mail::Sender doesn't require that the sendmail server be
on the computer you are sending the mail from. It is a rather unique mail
sending mod. I encourage you to check it out if you are going to be doing
any real mail programming.
The $file can be anything from plain text to html text. Your choice.
You can find out more about this mod at :
http://jenda.krynicky.cz/perl/Sender.pm.html
#! /usr/local/bin/perl -w
use strict;
use Mail::Sender;
my $recipients = 'test\@yourhost.com';
my $subject = 'What ever';
my $from = 'me\@yourhost.com';
my $url = '127.0.0.1'; # your host IP here;
$in = 'myHTML.txt';
my $file = "";
open(IN, "$in") or die "failed to open text message : $!";
while(<IN>)
{
$file .= $_;
}
close IN;
&sendmail($recipients, $subject, $from, $url, $file);
#--------------------------------------------------------------------------#
#--------------------------------------------------------------------------#
sub sendmail
{
my $recipients = shift;
my $subject = shift;
my $from = shift;
my $url = shift;
my $file = shift;
my $time = time;
$time = rand($time);
my $sender = new Mail::Sender {smtp => $url};
if (ref $sender->OpenMultipart({
from => $from,
to => $recipients,
subject => $subject,
boundary => 'boundary--'.$time,
type => 'multipart/related'})) {
$sender->Attach(
{description => 'html body',
ctype => 'text/html; charset=us-ascii',
encoding => '7bit',
disposition => 'NONE',
file => $file
});
$sender->Close() or die "Close failed! $Mail::Sender::Error\n";
} else {
die "Cannot send mail: $Mail::Sender::Error\n";
}
}
#--------------------------------------------------------------------------#
#--------------------------------------------------------------------------#
have a good time and good luck in your future Perl code.
webadept-ga