in reply to Re: Net::SMTP format
in thread Net::SMTP format
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;
|
|---|