S
sadie-no-reply
I am trying to post a message to a newsgroup using Net::NNTP, but I keep
getting an error message. Help!
I can read from the newsgroup without problems and $nntp->postok() gives OK.
I suspect there's something wrong with way I've constructed my message
array.
Here's the code.
use Net::NNTP;
$server="news.yourserver.com"; #replace this with your nntp server name
#connect to the nntp server (this works fine)
$nntp = Net::NNTP->new($server);
#open a newsgroup (this works fine)
$nntp->group("nl.test") or die "cannot open nl.test";
#download and print the last message (this works fine)
$articleId = $nntp->last();
@tekst = $nntp->article($articleId);
for ($i=1; $t=$tekst[0][$i]; $i++)
{print $t."<BR>\n";}
#check if I'm alowed to post (returns: ok)
if ($nntp->postok())
{print "Posting would be ok\n";}else
{print "Posting not ok\n";}
#construct a message - I'm not sure about this.
#For example, should there be \r\n at the end of each line??
@message=(
"Subject: this is test 1\r\n",
"From: cllq\@noreply.nil\r\n",
"Newsgroups: nl.test\r\n",
"Date: Sat, 3 Mar 2007 20:14:13 +0100\r\n",
"\r\n",
"This is my message\r\n",
"Yours sincerely\r\n",
"Bla\r\n");
#now post the message
$nntp->post(@message) or die "post failed"; #this one fails, but why?
$nntp->quit();
#alternative code that also fails:
$nntp->post() or die "post failed"; #this one ok
$nntp->datasend(@message) or die "datasend nok"; #this one ok
$nntp->dataend() or die "dataend nok"; #this one fails but why?
$nntp->quit();
getting an error message. Help!
I can read from the newsgroup without problems and $nntp->postok() gives OK.
I suspect there's something wrong with way I've constructed my message
array.
Here's the code.
use Net::NNTP;
$server="news.yourserver.com"; #replace this with your nntp server name
#connect to the nntp server (this works fine)
$nntp = Net::NNTP->new($server);
#open a newsgroup (this works fine)
$nntp->group("nl.test") or die "cannot open nl.test";
#download and print the last message (this works fine)
$articleId = $nntp->last();
@tekst = $nntp->article($articleId);
for ($i=1; $t=$tekst[0][$i]; $i++)
{print $t."<BR>\n";}
#check if I'm alowed to post (returns: ok)
if ($nntp->postok())
{print "Posting would be ok\n";}else
{print "Posting not ok\n";}
#construct a message - I'm not sure about this.
#For example, should there be \r\n at the end of each line??
@message=(
"Subject: this is test 1\r\n",
"From: cllq\@noreply.nil\r\n",
"Newsgroups: nl.test\r\n",
"Date: Sat, 3 Mar 2007 20:14:13 +0100\r\n",
"\r\n",
"This is my message\r\n",
"Yours sincerely\r\n",
"Bla\r\n");
#now post the message
$nntp->post(@message) or die "post failed"; #this one fails, but why?
$nntp->quit();
#alternative code that also fails:
$nntp->post() or die "post failed"; #this one ok
$nntp->datasend(@message) or die "datasend nok"; #this one ok
$nntp->dataend() or die "dataend nok"; #this one fails but why?
$nntp->quit();