#!/usr/bin/perl use strict; use warnings; use MIME::Entity; use Net::SMTP; use MIME::Types; my $mimetypes = MIME::Types->new; my $from = 'bt-user@localhost'; my $to = 'bt-user@localhost'; # Get File details my $file2attach = "/tmp/data.html"; #Create MIME entity my $mime = MIME::Entity->build( From => $from, To => $to, Subject => "This is a subject", Data => " This is the mail body :)", ); $mime->attach( Path => $file2attach, Type => ($mimetypes->mimeTypeOf($file2attach) || "application/octet-stream"), Encoding => '-SUGGEST', ); # SEND Mail my $smtp = Net::SMTP->new('localhost'); $smtp->mail($from); $smtp->to($to); $smtp->data(); $smtp->datasend($mime->stringify); $smtp->dataend(); $smtp->quit;