Hello,
Would you be so kind as to help me out?
I'm trying to set up a web page through which visitors can send me emails with attachments, and then use Perl behind the scenes to process the incoming content and send everything to me. With the code below (simplified for asking this question), I've succeeded in attaching and sending files already existing on the web server.
use Net::SMTP; use strict; use warnings; use MIME::Base64 qw( encode_base64 ); print "Content-type: text/html\n\n"; print "<html>\n<head>\n</head>\n<body>\n"; my $from = 'tester@mydomain.com'; my $to = 'myalias@mydomain.com'; my $attachBinaryFileName = 'test.jpg'; my $attachTextFileName = 'testattach.txt'; my $boundary = 'frontier'; my $smtp = Net::SMTP->new('mail.mydomain.com', Timeout => 10) || die(" +Could not create SMTP object."); $smtp->mail($from); $smtp->recipient($to, { SkipBad => 1 }); $smtp->data(); $smtp->datasend("To: $to\n"); $smtp->datasend("From: $from\n"); $smtp->datasend("Subject: Multi part test\n"); $smtp->datasend("MIME-Version: 1.0\n"); $smtp->datasend("Content-type: multipart/mixed;\n\tboundary=\"$boundar +y\"\n"); #$smtp->datasend("\n"); $smtp->datasend("--$boundary\n"); $smtp->datasend("Content-type: text/plain\n"); $smtp->datasend("Content-Disposition: quoted-printable\n"); $smtp->datasend("\nToday\'s files are attached:\n"); $smtp->datasend("\nHave a nice day! :)\n"); $smtp->datasend("--$boundary\n"); $smtp->datasend("Content-Type: application/text; name=\"$attachTextFil +eName\"\n"); $smtp->datasend("Content-Disposition: attachment; filename=\"$attachTe +xtFileName\"\n"); $smtp->datasend("\n"); $smtp->datasend("--$boundary\n"); $smtp->datasend("Content-Type: image/jpeg; name=\"$attachBinaryFileNam +e\"\n"); $smtp->datasend("Content-Transfer-Encoding: base64\n"); $smtp->datasend("Content-Disposition: attachment; filename=\"$attachBi +naryFileName\"\n"); $smtp->datasend("\n"); my $buf; open(DAT, "$attachBinaryFileName") || die("Could not open binary file! +"); binmode(DAT); local $/=undef; while (read(DAT, my $binaryfile, 114)) { $buf = &encode_base64( $binaryfile ); $smtp->datasend($buf); } close(DAT); $smtp->datasend("\n"); $smtp->datasend("--$boundary\n"); $smtp->dataend(); $smtp->quit;
What I'm having trouble with, is understanding how to fetch and send files that a visitor selects from their local computer. I don't know if I'm using the right Perl modules or right html form elements and what to put in the Perl script to fetch and attach the data.
On the html form, I've got:
<form action="mailscript.pl" method="post" enctype="multipart/form-dat +a"> <p>Name: <input type="text" name="sender_name" /></p> <p>Upload file 1: <input type="file" name="file1" /></p> <p>Upload file 2: <input type="file" name="file2" /></p> <p>Your Email Address: <input type="text" name="email_address" /></p> <p><input type="submit" name="Submit" value="Submit Form" /></p> </form>
What are your suggestions? Thanks in advance!
In reply to How do I fetch and send mail attachments? by Seeker100
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |