MIME::Lite should also rate a mention. Here is an example:

sub send_message { # args passed in %global, make sure all vals defined $global{$_} ||= '' for qw( to cc bcc reply_to subject message_ref +msg_body ); # lets include the time in the correct format, corrected for serve +r offset $TIME_OFFSET = '+0000' unless $TIME_OFFSET =~ m/^[+-]?\d\d\d\d\z/; require POSIX; my $date = POSIX::strftime("%a, %d %b %Y %H:%M:%S ", gmtime(time() +) ); $date .= $TIME_OFFSET; # split the to's,cc's, and bcc's my @to = split(/\s*[,;]\s*/, $global{to}) if $global{to}; my @cc = split(/\s*[,;]\s*/, $global{cc}) if $global{cc}; my @bcc = split(/\s*[,;]\s*/, $global{bcc}) if $global{bcc}; # clean up the message body newlines to spec $global{msg_body} =~ s/\015\012/\012/g; # get a new MIME::Lite object my $msg = MIME::Lite->new( From => "$global{username}\@$HOST_NAME", To => join(', ', @to), Cc => join(', ', @cc), Bcc => join(', ', @bcc), 'Reply-To' => $global{reply_to}, Subject => $global{subject}, Date => $date, 'X-Mailer' => "Our mailer 1.0", 'References' => $global{message_ref}, 'In-Reply-To' => $global{message_ref}, Type => "TEXT", Data => $global{msg_body} ); # add attachments for my $num ( 1..12 ) { next unless $q->param("attachment$num"); my $fh = $q->upload("attachment$num"); # make file names nice and fix a bug in Internet Exploder my ($filename) = $q->param("attachment$num") =~ m!([^/\\:]+)\z +!; $msg->attach( Type => "AUTO", Filename => $filename, FH => $fh ); } $msg->send(); }

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: Sending txt attachment in Email by tachyon
in thread Sending txt attachment in Email by jmaya

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.