Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm working on a script for posting html/image.

I've looked into NNTPClient, my lack of experience with perl is keeping me from getting the mime types to do html/images right what would be the best way for me to do this? or what modules would help the most?

#!/usr/local/bin/perl -w use News::NNTPClient; $c = new News::NNTPClient; if ($c->postok()) { $c->post("Newsgroups: test", "Subject: test", "From: test\@test.org", "", "This is only a test"); } __END__

Replies are listed 'Best First'.
Re: nntp posting (Moved from Q&A)
by chromatic (Archbishop) on Oct 30, 2000 at 10:20 UTC
    I would expect that MIME::Base64 would come in handy. The answer to this is probably similar to the answer to the question 'How do I attach a file to an e-mail', in which case you should hearken to some sort of MIME or Uuencode module to convert a binary file into something able to travel through the binary-unfriendly NNTP channels.

    It appears from a brief perusal of the NNTPClient documentation that you will have to turn your plain HTML and images into one single message body and send that in your post() call.

    Anyone who has more experience with this module or NNTP posting through Perl is welcome to correct me.

      #!/usr/bin/perl -w use News::NNTPClient; use MIME::Lite; $msg = MIME::Lite->new( To =>'news.directlink.net', Subject =>'HTML with in-line images!', Type =>'multipart/related' ); $msg->attach(Type => 'text/html', Data => qq{ <body> Here's <i>my</i> image: <img src="cid:myimage.gif"> </body> } ); $msg->attach(Type => 'image/gif', Id => 'myimage.gif', Path => '/usr/X11R6/share/IglooFTP/html/images +/viglooftp.gif', ); $c = new News::NNTPClient("news.bleh.com"); if ($c->postok()) { @header = ("Newsgroups: testing", "Subject: he234llo123", "From: test\ +@test.org"); @body = ("$msg"); $c->post(@header, "", @body); } __END__
      can't figure out what i'm doing wrong the posted output end sup a MIME::Lite=hashblehbleh
        You can't "stringify" a MIME::Lite object by simply referring to it in a string context. Your relevant line of code needs to be changed slightly:
        $body = $msg->as_string;
        Or use @body, whatever. Your post could also use some <code> tags, but I guess you can't fix it if you're not logged in.