barakuda has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I have a question about Net::SMTP module... now I know what you tinking, why don't I use MIME:Lite or such? Well, because the script will be run from the server and the only available module is Net::SMTP.
With that out of the way, on to the code:
my $smtp = Net::SMTP->new($host); $smtp->mail($myemail); $smtp->to(@emails); # Start the mail $smtp->data(); my $dispName = "Test Attachment"; # Send the header. $smtp->datasend("To: Myself\n"); $smtp->datasend("From: Me\n"); $smtp->datasend("Reply-To: $myemail\n"); $smtp->datasend("Subject: Test email\n"); $smtp->datasend("Content-Disposition: attachment; filename= $dispName\ +n"); ???? Is this right ??? $smtp->datasend("MIME-Version: 1.0\n"); $smtp->datasend('Content-Type: multipart/mixed; boundary= "--*B*--"\n\ +n'); ??? Is this right ???? # Send the body. $smtp->datasend("--*B*--\n"); $smtp->datasend("Content-Type: text/plain\n"); $smtp->datasend("This is a test email\n\n"); # Send attachemnt my $buffer = ""; my $file = "Test.txt"; open (MAIL, "<$file") or die "ERROR: Could not open email file"; while (<MAIL>) {$buffer .= $_} close (MAIL); $smtp->datasend("--*B*--\n"); $smtp->datasend("Content-Type: application/text; name= \"$file\" \n"); + ???? Is this right???? $smtp->datasend("\n"); $smtp->datasend("$buffer\n\n"); # Finish sending the mail $smtp->dataend(); # Close the SMTP connection $smtp->quit;
What this gives me is some file (with unrecognized extension) as an attachemtn, and no text in the body (I think the body went into the file)
So, wherever you see "??? Is that right ???" is where the problems are likely to be comming from... since I don't fully understand how those lines work.
Any help will be appreciated!
P.S. what I am trying to do is send some text in the body of the message, as well as a text file as attachemnt
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::SMTP format
by samtregar (Abbot) on Mar 12, 2008 at 15:40 UTC | |
by barakuda (Initiate) on Mar 12, 2008 at 16:27 UTC | |
|
Re: Net::SMTP format
by NetWallah (Canon) on Mar 12, 2008 at 15:33 UTC |