That example you point to appears to be a complete script, but is not.. you have to devise a way to get your desired attachment into
$file, and also devise a way to attach more than one file...
About
$file = $^X; it appears the author just picked a random file to assign to
$file for this particular example, so why not pick the perl executable itself, and hey why not use one of the builtin shorthands instead of typing "/usr/bin/perl".. Trés Geeky, non?
So to follow on the rest of this block:
open (F, $file) or die "Cannot read $file: $!";
binmode F; undef $/;
$mail{body} = encode_base64(<F>);
close F;
- Open $file for reading, with handle F.
- Treat it as a binary file (we know it probably wil not contain line ending characters), intending the attachment to be encoded as one input stream.
- Remove the normal assignment of the input record separator $/ (usually newline), this input won't need it. IMO that should be done within a sub, since it's never reset when the operation there finishes..
-The hash %mail already exists, assign new element "body" to contain the base64 encoded stream of $file.
There are a few Perl modules usable to create file attachments .. I keep recommending
Mail::SendEasy because it is so simple and cool.. no dependencies, it takes about 3 minutes to learn what it does and be up and running...
-Harold
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.