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


In reply to Net::SMTP format by barakuda

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.