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; }

In reply to Re: send contents of a file in mail by harangzsolt33
in thread send contents of a file in mail by noviceuser

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.