in reply to Net::SMTP format

I see one obvious problem:

$smtp->datasend('Content-Type: multipart/mixed; boundary="--*B*--"\n\n +');

You're using single quotes and trying to include escape sequences. Those won't be processed and you'll end up with raw \n in your message. Instead:

$smtp->datasend(qq{Content-Type: multipart/mixed; boundary="--*B*--"\n +\n});

As far as getting the rest of the MIME encoding right you're going to have to read the specs or copy the code. Personally I'd work on figuring out how to get MIME::Lite installed on the server instead.

-sam

Replies are listed 'Best First'.
Re^2: Net::SMTP format
by barakuda (Initiate) on Mar 12, 2008 at 16:27 UTC

    It all turned out to be simpler than I thought.
    Just remember: LEAVE A BLANK LINE AFTER "Content Type: " setting
    Simple as that. So, here's the working code for sending text along with an attached file:

    my $smtp = Net::SMTP->new($host); $smtp->mail($myemail); $smtp->to(@emails); # Start the mail $smtp->data(); # Send the header. There needs to be a newline at the end of each line $smtp->datasend("To: Myself\n"); $smtp->datasend("From: Me\n"); $smtp->datasend("Reply-To: oakulov\@rim.com\n"); $smtp->datasend("Subject: Test email\n"); $smtp->datasend("MIME-Version: 1.0\n"); $smtp->datasend("Content-Type: multipart/mixed; boundary= \"*BCKTR*\"\ +n\n"); # Send the body. $smtp->datasend("--*BCKTR*\n"); $smtp->datasend("Content-Type: text/plain\n\n"); # this is a formatti +ng command, so leave an extra line between it and the text $smtp->datasend("This is a test email\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("--*BCKTR*\n"); $smtp->datasend("Content-Type: text/plain; name= \"$file\" \n"); $smtp->datasend("Content-Disposition: attachment; filename= \"$file\"\ +n\n"); $smtp->datasend("$buffer\n\n"); # Send the END section break $smtp->datasend("--*BCKTR*--\n\n"); # Finish sending the mail $smtp->dataend(); # Close the SMTP connection $smtp->quit;