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

Dear Gurus, I am using MIME:Lite and a Mail subroutine that I wrote that makes it easy to send out emails with attachments. the code works well for Excel, Word, Pdf and Text files, but it does not work with a file that has an extension .inf but is really a text file. (I was sent the file by another company or I would have ended it in .txt!) I have tried defining a variety of Mimetypes for this file but it just won't email. Can you give me some guidance? Note - The .xnf and .znf extensions referred to below are actually some of the derivations I tried. They were originally put in as .inf.

sub Mail { my($addr,$subj,$body,$attach,$replyaddr,$cclist,$bcclist,$contentt +ype,$onbehalfof) = @_; #Set the name of the sender as it appears in the user's inbox $onbehalfof = $onbehalfof || 'MyCompany <Reports@mycompany.com>'; $replyaddr = $replyaddr || 'Reports@mycompany.com'; #Set the content type (text or html) $contenttype = ($contenttype =~ /^html$/i) ? $MIME_BODYHTML : ($contenttype) ? $contenttype : $MIME_BODYTEXT; #Format cc and bcc lists $cclist =~ s/\;/\,/; $bcclist =~ s/\;/\,/; ### Create a new multipart message: $msg = MIME::Lite->new( From =>"$onbehalfof", To =>"$addr", CC => "$cclist", BCC => "$bcclist", Subject =>"$subj", Type =>'multipart/mixed', 'Reply-To' => "$replyaddr" ); ## Add body text ## $msg->attach( Type =>"$contenttype", Data =>"$body" ); ## Add any attachments ## #Multiple file support @attachfile = split /;/,$attach; while ($attachf = shift (@attachfile)) { if (defined($attachf)){ undef $attachtype; my $attachtype = getmimetype($attachf); # $attachtype = 'application/msword'; print "File ${attachf} is ${attachtype}\n"; $msg->attach( Path => "$attachf", Type => "$attachtype", Disposition => 'attachment' ); } } $smtpserv = $smtpserver; $msg->send('smtp',$smtpserv, Debug=>0); } sub getmimetype { my ($file) = @_; fileparse_set_fstype("MSWin32"); my($name,$path,$extension) = fileparse("$file", '.\w+'); my %MIMETYPES = ( ".doc" => 'application/x-msword', ".dot" => 'application/x-msword', ".wrd" => 'application/x-msword', ".xls" => 'application/vnd.ms-excel', ".xlt" => 'application/vnd.ms-excel', ".pdf" => "application/pdf", ".txt" => "application/txt", ".xnf" => "application/x-setupscript", ".znf" => "application/inf" ); my $mimetype = $MIMETYPES{$extension}; $mimetype = $mimetype || 'text/plain'; return $mimetype; }

Replies are listed 'Best First'.
Re: Can't Send a File of Unknown Mimetype
by thomas895 (Deacon) on May 02, 2012 at 23:00 UTC

    From what I know, the MIME type is only used as a helper for the client. It is considered "courteous" for the sender to include it, but you could probably use application/octet-stream if you are unsure.

    ~Thomas~ I believe that the source code to life is written in Perl :-)
Re: Can't Send a File of Unknown Mimetype
by sauoq (Abbot) on May 03, 2012 at 00:34 UTC
    but it just won't email.

    This might sound like a stupid question, but it isn't: how do you know it "won't email"?

    -sauoq
    "My two cents aren't worth a dime.";
Re: Can't Send a File of Unknown Mimetype
by zentara (Cardinal) on May 03, 2012 at 10:24 UTC
    but it just won't email.

    I recall seeing this problem once before, but it was a problem on the server, which just wouldn't accept certain types of files. My guess is that it was some futile attempt by an amateur Microsoft coder to prevent viruses. I ended up zipping the file up, and it went thru. As sauog said, how do you know it dosn't send? What error messages do you get, and where in the script does it appear?


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh