Library tutorials & articles

How to NNTP in C#

Using the NNTP class

Using our NNTP class is quite trivial. An example follows.

static void Main(string[] args)
{
    try
    {
        Nntp obj = new Nntp();
        obj.Connect(" news.devx.com");
        ArrayList list = obj.GetNewsgroups();
        foreach (string newsgroup in list)
        {
            System.Console.WriteLine(" Newsgroup :{0}",
                newsgroup);
        }
        list = obj.GetNews(" test");
        foreach (string article in list)
        {
            System.Console.WriteLine("{0}", article);
        }
        obj.Post(" test", "Hello",
            "randy@ kbcafe.com (Randy Charles Morin)", "Goodbye");
        obj.Disconnect();
    }
    catch (NntpException e )
    {
        System.Console.WriteLine(e.ToString());
    }
    catch (System.Exception )
    {
        System.Console.WriteLine(" Unhandled Exception");
    }
}

Instantiate an Nntp object and call Connect passing the NNTP server name. Then we can repeatedly call GetNewsgroups, GetNews and Post to receive and post articles in the forums found on the NNTP server. Finally you call the Disconnect method to release the socket connection to our NNTP server.

The RFC for NNTP is RFC 977 and can be found at the IETF website. You should also review the RFC for the USENET news message format as presented in RFC 850.

Comments

  1. 08 Apr 2006 at 22:54

    Great article - thanks. 

    However I'd like to post HTML to an NNTP server.  I'm assuming that I need to specify this in the Header info somehow but can't find any documentation on NNTP message headers.

    Could you shed some light here.

    Thanks again

     

  2. 20 Apr 2005 at 21:35

    The only problem I found with this article, was the missing "Supporting Functions" you included in your other programs.  Other than that, this is an awesome article!  Keep up the good work!

  3. 01 Oct 2004 at 08:59


    This saved me days of work ! Thanks, really excellent.

  4. 01 Jan 1999 at 00:00

    This thread is for discussions of How to NNTP in C#.

Leave a comment

Sign in or Join us (it's free).

Randy Charles Morin Randy's article are Copyright 1998-2003 Randy Charles Morin

Related podcasts

  • Object-Oriented Programming in Ruby

    In this episode, I talk with Scott Bellware about object-oriented programming in Ruby, and Ruby's object model. This is taken from a private conversation, and the audio quality suffers at times. Much thanks to Scott for allowing this to be released.This episode of the Alt.NET Podcast is bro...

We'd love to hear what you think! Submit ideas or give us feedback