Send Email with Attachment using Perl



If you want to send an attachment in your email using Perl, then following script serves the purpose −

#!/usr/bin/perl
use MIME::Lite;
$to = '[email protected]';
$cc = '[email protected]';
$from = '[email protected]';
$subject = 'Test Email';
$message = 'This is test email sent by Perl Script';
$msg = MIME::Lite-=>new(
   From => $from,
   To => $to,
   Cc => $cc,
   Subject => $subject,
   Type => 'multipart/mixed'
);
# Add your text message.
$msg->attach(
   Type => 'text',
   Data => $message
);
# Specify your file as attachement.
$msg->attach(Type => 'image/gif',
   Path => '/tmp/logo.gif',
   Filename => 'logo.gif',
   Disposition => 'attachment'
);
$msg->send;
print "Email Sent Successfully\n";

You can attach as many files as you like in your email using attach() method.

Updated on: 2019-11-29T12:15:51+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements