#!/usr/bin/perl use strict; use MIME::Lite; my $DEBUG = 0; my %TYPES = ( csv => [ 'text/csv', '8bit' ], gif => [ 'image/gif', 'base64' ], tiff => [ 'image/tiff', 'base64' ], tif => [ 'image/tiff', 'base64' ], jpeg => [ 'image/jpeg', 'base64' ], jpg => [ 'image/jpeg', 'base64' ], zip => [ 'application/zip', 'base64' ], gz => [ 'application/gzip', 'base64' ], html => [ 'text/html', '8bit' ], htm => [ 'text/html', '8bit' ], pdf => [ 'application/pdf', 'base64' ], ); { my $subject = shift; my $filetype = shift; my $filename = shift; my $email = shift; die "Usage: $0 subject file-type filename email\n" unless ( $email ); my %mail = ( subject => $subject, to => $email, from => 'webmaster@intes.net' ); my $msg = new MIME::Lite( From => $mail{from}, To => $mail{to}, Subject => $mail{subject}, Data => 'Emailing file; should be attached', Type => 'text/plain' ); my $type = $TYPES{ lc $filetype } || [ 'text/plain', '8bit' ]; $msg->attach( Type => $type->[0], Encoding => $type->[1], Path => $filename ); MIME::Lite->send( 'smtp', 'localhost', Timeout => 20 ); $msg->send || die "Cannot send message: $!"; }