opendir DIR, "$TEMP_DIR/" or &file_error("Unable to open directory. $!"); readdir DIR for 0 .. 1; @files = grep -f "$TEMP_DIR/$_", readdir DIR; closedir DIR; my %hash; foreach my $filename (@files) { my($base) = $filename =~ /(.+?)\..+?$/; $hash{$base} = $filename; } my $MailAttachment = "$TEMP_DIR/" . $hash{$SessionID}; my $ext = (split /\./, $MailAttachment)[-1]; my $picturename = "bild"; if (!-e $MailAttachment) {&program_error("Keine Datei vorhanden. $!");} use MIME::Lite; # Create a new multipart message: $msg = MIME::Lite->new( From =>"$CompanyName <$CompanyEmail>", To =>"$CompanyName <$CompanyEmail>", Cc =>'', Subject =>"Nachricht von $company", Type =>'multipart/mixed' ); # Add parts (each "attach" has same arguments as "new"): $msg->attach(Type => 'text/html', Data => qq { bla, bla } ); # Add the attachment and automaticly determine the content type: $MIME::Lite::AUTO_CONTENT_TYPE = 1; $msg->attach( Type =>'auto', Path =>"$MailAttachment", Filename =>"$picturename.$ext", Disposition =>'attachment' ); $msg->send;