http://www.perlmonks.org?node_id=914069

perlaki has asked for the wisdom of the Perl Monks concerning the following question:

I'm using MIME::Entity module to send an email. In that i'm facing one issue. If i sent any attachment file, I'm getting attached file content in body as well file also attached in that mail. I have copied some part of code which i'm using to send an email.

## Open sendmail via pipe $fh = new FileHandle(); ## -t = Scan's the input for recipient headers. ## -oi = Set interactive delivery mode. ## -oem = Enable BerkNet processing, and mail back for errors unless ($fh->open("|/usr/lib/sendmail -t -oi -oem")) { ## Failed to open sendmail #error_log("Unable to open pipe for sendmail.", $!, $main::prog,'email_delivery', 'FATAL', 'ERROR'); print "Unable to open pipe for sendmail. $!, $main::prog,'email_ +delivery', 'FATAL', 'ERROR'"; return 0; ## failure ## } ## Build MIME message $message = MIME::Entity->build ( 'Type' => 'multipart/mixed', 'To' => $emailaddress, 'Subject' => $emailsubject, 'X-Mailer' => undef); ## Check if we received an object back unless (defined $message) { #error_log("MIME::Entity->build() failed to + return an object reference.", "", $main::prog, 'email_delivery','FAT +AL', 'ERROR'); print "MIME::Entity->build() failed to retu +rn an object reference., $main::prog, 'email_delivery','FATAL', 'ERR +OR'"; return 0; ## failure ## } ## Attach a message body $message->attach(Data => 'Your data has been a +ttached to this message.'); # Attach the file as an octet-stream $message->attach(Type => 'application/octet-st +ream', Path => $infile, Encoding => 'base64') +; $message->print($fh); $fh->close();

Note :
If I send any file with out extension, then the file is coming only in attachment, the file content will not display in body. Else, I send any file with extension, then only the file content is copying in body and file also coming in attachment.
Can any one please help me to resolve the issue.
Thanks in advance.