meers1974
asked on
Email through Perl
I am trying to send an email through perl and I get the following error message..Can someone help resolve this error.. Thanks.
Error:
Can't locate object method "new" via package "MIME::Lite" (perhaps you forgot to
load "MIME::Lite"?) at mail.pl line 23.
Here is the code:
-------------------
#!perl
# use MIME::Lite package
use MIME::Lite;
# set up email
$to = "xyz@email.com";
$from = "abc@email.com";
$subject = "Email Sent via Perl";
$message = "This email was sent using Perl.";
$file = "c:\email.txt";
# send email
email($to, $from, $subject, $message, $file);
# email function
sub email
{
# get incoming parameters
local ($to, $from, $subject, $message, $file) = @_;
# create a new message
$msg = MIME::Lite->new(
From => $from,
To => $to,
Subject => $subject,
Data => $message
);
# add the attachment
$msg->attach(
Type => "text/plain",
Path => $file,
Filename => $file,
Disposition => "attachment"
);
# send the email
MIME::Lite->send('smtp', 'mail.example.com', Timeout => 60);
$msg->send();
}
Error:
Can't locate object method "new" via package "MIME::Lite" (perhaps you forgot to
load "MIME::Lite"?) at mail.pl line 23.
Here is the code:
-------------------
#!perl
# use MIME::Lite package
use MIME::Lite;
# set up email
$to = "xyz@email.com";
$from = "abc@email.com";
$subject = "Email Sent via Perl";
$message = "This email was sent using Perl.";
$file = "c:\email.txt";
# send email
email($to, $from, $subject, $message, $file);
# email function
sub email
{
# get incoming parameters
local ($to, $from, $subject, $message, $file) = @_;
# create a new message
$msg = MIME::Lite->new(
From => $from,
To => $to,
Subject => $subject,
Data => $message
);
# add the attachment
$msg->attach(
Type => "text/plain",
Path => $file,
Filename => $file,
Disposition => "attachment"
);
# send the email
MIME::Lite->send('smtp', 'mail.example.com', Timeout => 60);
$msg->send();
}
Start by using single quotes when assigning $to and $from. Using the double quotes could be causing an issue with a "possible unintended interpolation of @email in string", which could be the root cause of your error.
Also, verify that the MIME::Lite module is installed. There are several methods to do the verification, here's one.
perl -MMIME::Lite -e "print 'module is installed';"
perl -MMIME::Lite -e "print 'module is installed';"
ASKER
The module seems to be installed.
perl -MMIME::Lite -e "print 'module is installed';"
module is installed
I tried single quotes.. didn't work.
# set up email
$to = 'xyz@email.com';
$from = 'abc@email.com';
perl -MMIME::Lite -e "print 'module is installed';"
module is installed
I tried single quotes.. didn't work.
# set up email
$to = 'xyz@email.com';
$from = 'abc@email.com';
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.