Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

RE: sending email

by lachoy (Parson)
on Oct 13, 2000 at 17:33 UTC ( #36579=note: print w/ replies, xml ) Need Help??


in reply to sending email

I find Mail::Sendmail to be easy, reliable and cross-platform.

However, also note that sending mail with attachments is really easy with MIME::Lite (although you need to install Net::SMTP to use this, as other folks have noted). MIME::Lite is available through Activestate's PPM, which makes life easier.

Check out this simple cross-platform (tested on Linux and NT). NT gives an annoying: "The system cannot find the path specified" error, but still works.

There are, of course, lots of ways to improve it (use a 'magic' file to discern the MIME type, use Getopt::Long for a more coherent command line, allow the user to set more parameters, etc.)

#!/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@in +tes.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: $!"; }


Comment on RE: sending email
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://36579]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2014-12-18 07:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (44 votes), past polls