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

I've gotten Net::NNTP working quite nicely except for one small matter: I can't figure out how to post a message to a newsgroup using the post() function.

The NNTP docs state (edited for brevity):

> post ( [ MESSAGE ] ) > Post a new article to the news server... MESSAGE can be eith +er an array of lines or a reference to an array.
What would this array contain and in what format would the array elements be? (I've read rfc850 so I know what content needs to be there, but would someone as to show me how to implement it?)

Cheers,
Chris

Replies are listed 'Best First'.
Re: Net::NNTP question
by chromatic (Archbishop) on Mar 13, 2001 at 04:01 UTC
    The array should contain the lines of the body of the post. Unless the newsgroup allows HTML posting, each line should be in plain text format.

    You might use Text::Wrap to make sure no line is longer than 72-characters, to be a good Netizen. I suppose you could also use Mime-Tools (from the CPAN) to encode a binary, then post it.

Re: Net::NNTP question
by njh@bandsman.co.uk (Acolyte) on Dec 31, 2002 at 10:37 UTC
    Try this. -Nigel
    #!/usr/bin/perl -w use strict; use Net::NNTP; my $server = Net::NNTP->new('your.news.server') or die "Can't connect to news server: $@\n"; $server->postok() or die "Can't post to news server\n"; my @lines = ( "From: Nigel Horne <njh\@despammed.com>\n", "Newsgroups: alt.test\n", "Subject: a test posting\n", "Content-Transfer-Encoding: quoted-printable\n", "Content-Type: text/plain; charset=ISO-8859-1;\n", "\n", "A test message\n" ); print (@lines); $server->post(@lines); $server->quit();