bruce
09-02-2003, 03:24 AM
Many of you have asked how to use email COM objects (ASPMail, JMail, CDO, etc) to send mail in Perl.
Here's an example
use Win32::OLE;
print "COntent-type: text/html\n\n";
sendmail('source_address@xyz.com','to_address@xyz. com','subject','message');
sub sendmail
{
my ($from,$to,$subject,$body) = @_;
my $m = Win32::OLE->new('JMail.SMTPMail') || die "Can't create
JMail.SMTPMail";
$m->{ServerAddress} = 'localhost';
$m->{Subject} = $subject;
$m->{Body} = $body;
$m->{Sender} = $from;
$m->AddRecipient($to);
if (! $m->Execute)
{
warn "mail error $m->{ErrorCode}($m->{ErrorSource})
$m->{ErrorMessage}";
}
}
Here's an example
use Win32::OLE;
print "COntent-type: text/html\n\n";
sendmail('source_address@xyz.com','to_address@xyz. com','subject','message');
sub sendmail
{
my ($from,$to,$subject,$body) = @_;
my $m = Win32::OLE->new('JMail.SMTPMail') || die "Can't create
JMail.SMTPMail";
$m->{ServerAddress} = 'localhost';
$m->{Subject} = $subject;
$m->{Body} = $body;
$m->{Sender} = $from;
$m->AddRecipient($to);
if (! $m->Execute)
{
warn "mail error $m->{ErrorCode}($m->{ErrorSource})
$m->{ErrorMessage}";
}
}