Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Sending txt attachment in Email

by jmaya (Acolyte)
on Mar 26, 2003 at 03:42 UTC ( [id://245853]=perlquestion: print w/replies, xml ) Need Help??

jmaya has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to write a script that sends a file .txt as an attachment or an html file "AS atachment" but i cannot find a way of doing so. Any ideas?

Replies are listed 'Best First'.
Re: Sending txt attachment in Email
by tachyon (Chancellor) on Mar 26, 2003 at 06:34 UTC

    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

Re: Sending txt attachment in Email
by pfaut (Priest) on Mar 26, 2003 at 03:58 UTC

    Look into Mime::Tools.

    --- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';
Re: Sending txt attachment in Email
by bbfu (Curate) on Mar 26, 2003 at 05:12 UTC

    Or Mail::Sender and its MailFile method.

    bbfu
    Black flowers blossom
    Fearless on my breath

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://245853]
Approved by pfaut
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-24 13:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found