PDA

View Full Version : How to use email COM object to send mail?


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}";
}
}

bruce
09-29-2004, 12:53 AM
We recently installed a new Perl module that allow you to send mail

See

http://alma.ch/perl/Mail-Sendmail-FAQ.html

[b]quote:Originally posted by bruce

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}";
}
}
</blockquote id="quote"></font id="quote">

B.

DiscountASP.NET
http://www.DiscountASP.NET