troubleshooting Question

Email through Perl

Avatar of meers1974
meers1974 asked on
Perl
4 Comments1 Solution438 ViewsLast Modified:
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();
}
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros