Hey, I was wondering if there is a way to attach files (specifically .csv files) to a mail message in Perl without using MIME::Lite or any other libraries.
Right now
General style tips to make your life easier:
Ie:
open my $mail, '|-', '/usr/sbin/sendmail', '-t' or Carp::croak("Cant start sendmail, $! $@");
print $mail "foo";
close $mail or Carp::croak("SendMail might have died! :( , $! $@");
perldoc -f open
If part of your problem is that you're on shared hosting and cannot install extra libraries, they can usually be installed in (and used from) a local a library (e.g., ~/lib). There are instructions for that over here (under "I don't have permission to install a module on the system!").
you can specify the mail-headers as :
Content-Type ie: image/jpeg; name="file.jpg"
Content-Disposition (ie ) attachment; filename="name.jpg"
Content-Transfer-Encoding (ie) base64
Look at an email sent with an attachment, that should help you out.
the trick is multipart boundaries.
http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
Why do you want to write code that already exists? There's probably a much better way to solve your task than recreating bugs and maintaining more code yourself. Are you having a problem installing modules? There are ways that you can distribute third-party modules with your code, too.
If you want to do it yourself, you just have to do the same things the module does for you. You can just look at the code to see what they did. You just do that. It is open source after all. :)
Example - Email a zipped file as an attachment:
base64 /path/to/my/file.zip | mail -s "Subject" recipient@mydomain.com -a 'Content-Type: application/zip; name="myfile.zip"' -a 'Content-Disposition: attachment' -a 'Content-Transfer-Encoding: base64'
print "To: "; my $to=<>; chomp $to;
print "From: "; my $from=<>; chomp $from;
print "Attach: "; my $attach=<>; chomp $attach;
print "Subject: "; my $subject=<>; chomp $subject;
print "Message: "; my $message=<>; chomp $message;
my $mail_fh = \*MAIL;
open $mail_fh, "|uuencode $attach $attach |mailx -m -s \"$subject\" -r $from $to";
print $mail_fh $message;
close($mail_fh);