sub Mail { my($addr,$subj,$body,$attach,$replyaddr,$cclist,$bcclist,$contenttype,$onbehalfof) = @_; #Set the name of the sender as it appears in the user's inbox $onbehalfof = $onbehalfof || 'MyCompany '; $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; }