Mailing multiple PNG attachments using sendmail

Need assistance in using the below script and having multiple png file attachments in the same script . Your inputs are appreciated. I dont have uuencode , I use either mailx, sendmail, mpack .

( echo "to: samplemail@somewhere.com"
  echo "from: samplemail@elsewhere.com"
  echo "subject: sending file.jpg"
  echo "mime-version: 1.0"
  echo "content-type: multipart/related; boundary=xxxRANDOMSTRINGxxx"
  echo
  echo "--xxxRANDOMSTRINGxxx"
  echo "content-type: text/plain"
  echo
  echo "Body of the message goes here"
  echo "Here is file.jpg for your viewing pleasure"
  echo
  echo "--xxxRANDOMSTRINGxxx"
  echo "content-type: image/gif; name=file.png"
  echo "content-transfer-encoding: base64"
  echo
  openssl base64 < file.png ) | sendmail -t -i

As far as I know uuencode , mailx, sendmail and mpack are all capable of sending an email with a single attachment. You should look at the various Perl libraries to see if one works for you. I have used MIME::Lite in the past. There are scripts that you can find online with your favorite search engine. Just add logic for additional attachments.

1 Like

Thank you very much gandolf989. It worked .

I installed the perl module "MIME-Lite-3.01.tar.gz" used the below code and it works great.

#!/usr/bin/perl

use MIME::Lite;

$from = 'qwerty\@erweer.com';
$to = 'abcd\@efgh.com';
$Subject = 'Hello';

# Part using which the attachment is sent to an email #
$msg = MIME::Lite->new(
        From     => $from,
        To       => $to,
        Subject  => $Subject,
        Type     => 'multipart/Mixed',
);
$msg->attach(
      Type     => 'Text', 
      Data     => "The attachment contains your file"
);
$msg->attach(
    Type     => 'Image/gif',
        Path         => "/abcd/M.gif"
);

print "Mail Sent\n";
$msg->send; # send via default