I would start out with something that works. I had a working perl script that sends an email, so I tried to extract only the relevant parts of that program, and I am only showing that here. I did not have a chance to test this program after removing 90% of the code, but I think it will still work.
#!/usr/bin/perl
use strict;
use warnings;
use MIME::Lite;
my $FROM = '"Senders Name" <youremail@email.com>';
my $TO = 'destination_email@email.com';
my $CC = 'second_destination@email.com'; # You may leave this blan
+k
my $SENDFILE = 'file_to_send.txt';
my $MAX_EMAIL_LENGTH = 1000000; # Don't send email if it's too large
my $DATA = ReadFile($SENDFILE);
$DATA = pack('u', $DATA); # Uuencode file contents
length($DATA) <= $MAX_EMAIL_LENGTH or die "\nThe email shouldn't be la
+rger than $MAX_EMAIL_LENGTH.\n";
# Send email
my $EMAIL_SUBJECT = "UUEncoded File";
my $HTML_MESSAGE = '';
my $TEXT_MESSAGE = "Here is your file:\n\n" . $DATA;
my $STATUS = SendMail($FROM, $TO, $CC, $EMAIL_SUBJECT, $TEXT_MESSAGE,
+$HTML_MESSAGE);
exit;
######################################################
# Reads an entire file in raw mode and returns the contents as a strin
+g.
# Usage: STRING = ReadFile(FILENAME)
sub ReadFile { my $NAME = shift; (-e $NAME && -f $NAME && -s $NAME) or
+ return ''; my $DATA; open my $FILE, '<:raw', $NAME or return ''; { l
+ocal $/; $DATA = <$FILE>; } close $FILE; return (defined $DATA) ? $DA
+TA : ''; }
# The SendMail() function sends an email with an attachment. Returns 1
+ on success or 0 on failure.
# Usage: INTEGER = SendMail(FROM, TO, CC, SUBJECT, TEXT_MESSAGE, HTML_
+MESSAGE)
sub SendMail
{
@_ == 6 or return 0;
my ($From, $To, $Cc, $Subject, $TEXT, $HTML) = @_;
my $EMAIL = MIME::Lite->new(
From => $From,
To => $To,
Cc => $Cc,
Subject => $Subject,
Type => 'multipart/mixed');
# Add text portion.
$EMAIL->attach(
Type => 'text',
Data => $TEXT);
# Add HTML portion.
$EMAIL->attach(
Type => 'text/html',
Disposition => 'inline',
Data => $HTML);
$EMAIL->send;
return 1;
}
|