in reply to Sending txt attachment in Email
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
|
|---|