Click here to Skip to main content
Licence 
First Posted 24 Jul 2005
Views 32,221
Bookmarked 11 times

Posting newsgroup messages with NNTP using Indy

By | 24 Jul 2005 | Article
In this article, I will demonstrate how to quickly and easily post a message to a newsgroup, including an attachment, using the Indy open source library.

Introduction

In this article, I will demonstrate how to quickly and easily post a message to a newsgroup, including an attachment, using the Indy open source library.

The Code

using (NNTP xNNTP = new NNTP()) {
  xNNTP.Connect("msnews.microsoft.com"); 
  try {
    Message xMsg = new Message(); 
    xMsg.Subject = "Test Message from Indy";
    xMsg.From.Address = "null@nowhere.com";
    xMsg.Body.Text = "This is a test message.";
    xMsg.NewsGroups.Add("microsoft.test");
    new AttachmentFile(xMsg.MessageParts, 
        System.Environment.CurrentDirectory + @"\..\..\App.ico");
    xNNTP.Post(xMsg);
    Console.WriteLine("Message posted");
  } finally {
    xNNTP.Disconnect();
  }
}

Running the Demo

The demo simply posts a test message to a test newsgroup on the Microsoft news server. To change it to your news server and newsgroup, simply change the parameters in the demo.

Output

The demo has very little output unless there is an error. To see the results, you should look at the microsoft.test newsgroup using your newsreader. Note that messages may not appear instantly and on the Microsoft server it sometimes takes a few minutes for the message to be visible publicly.

Why Console?

The demo code is a console application. For simple code snippets, I prefer console applications as they are easier to write and to focus on code without the demo being over-shadowed by the interface code. All of the code demonstrated here can of course be used in a WinForms, WebForms, Web services, or other types of applications.

What is Indy?

This demo uses classes from the open source Indy.Sockets library. Indy.Sockets is an open source socket library that supports clients, servers, TCP, UDP, raw sockets, as well as over 100 higher level protocols such as SMTP, POP3, NNTP, HTTP, and many more. Indy.Sockets is available for C#, C++, Delphi, and Visual Basic. NET. Indy runs on Windows, Linux, Microsoft .NET, and Mono.

The downloadable demo includes the Indy assembly so it is ready to run.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Chad Z. Hower aka Kudzu

Other

Cyprus Cyprus

Member

Chad Z. Hower, a.k.a. Kudzu
"Programming is an art form that fights back"
Website: http://www.KudzuWorld.com
Blogspace: http://www.KudzuWorld.com/blogs/
Speaking Profile: http://www.woo-hoo.net/
 
Formerly the Regional Developer Adviser (DPE) for Microsoft MEA (Middle East and Africa), he was responsible for 85 countries spanning 4 continents and crossing 10 time zones. Now Chad is Microsoft MVP and a professional speaker at popular developer conferences worldwide. Chad was once introduced as having "mastered more languages than a United Nations translator." Chad is the author of the book Indy in Depth and has contributed to several other books on network communications and general programming. Chad has lived in Canada, Cyprus, Switzerland, France, Jordan, Russia, Turkey, and the United States. In total Chad has visited more than 50 countries, visiting most of them many times.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
General[Message Deleted] Pinmemberit.ragester21:58 2 Apr '09  
GeneralMisleading Article Title PinmemberAshaman3:35 26 Jul '05  
I thought this was going to be an article about how to post newsgroup messages with the NNTP protocol.
 
I didn't realize that the article was really a copy/paste job from an open source socket library's manual.
 
What you have here is about 30 seconds of coding effort and an external dependency. Very disappointing.
GeneralRe: Misleading Article Title PinmemberMartin Robins8:32 28 Jul '05  
GeneralRe: Misleading Article Title Pinmemberundeclared8:56 12 Jul '08  
GeneralCool PinmemberSuper Lloyd17:31 24 Jul '05  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120529.1 | Last Updated 24 Jul 2005
Article Copyright 2005 by Chad Z. Hower aka Kudzu
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid