Click here to Skip to main content
6,294,871 members and growing! (17,176 online)
Email Password   helpLost your password?
General Programming » Internet / Network » Internet & Network     Intermediate

Posting newsgroup messages with NNTP using Indy

By Chad Z. Hower aka Kudzu

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.
C#, Windows, .NET 1.1VS.NET2003, Dev
Posted:24 Jul 2005
Views:23,968
Bookmarked:9 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
10 votes for this article.
Popularity: 2.63 Rating: 2.63 out of 5
7 votes, 70.0%
1

2

3
2 votes, 20.0%
4
1 vote, 10.0%
5

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


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 Microsoft Regional Director covering Europe, Middle East, Africa, and Asia 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 writes regularly for the Software Developer Network Magazine (Dutch), and occasionally for other magazines. Chad is an expatriate who travels extensively year round. Chad has lived in Canada, Cyprus, Jordan, Russia, Turkey, and the United States. In total Chad has visited more than 50 countries, visiting most of them many times.
Occupation: Software Developer (Senior)
Location: Cyprus Cyprus

Other popular Internet / Network articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 5 of 5 (Total in Forum: 5) (Refresh)FirstPrevNext
General[Message Deleted] Pinmemberit.ragester22:58 2 Apr '09  
GeneralMisleading Article Title PinmemberAshaman4:35 26 Jul '05  
GeneralRe: Misleading Article Title PinmemberMartin Robins9:32 28 Jul '05  
GeneralRe: Misleading Article Title Pinmemberundeclared9:56 12 Jul '08  
GeneralCool PinmemberSuper Lloyd18:31 24 Jul '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 24 Jul 2005
Editor: Smitha Vijayan
Copyright 2005 by Chad Z. Hower aka Kudzu
Everything else Copyright © CodeProject, 1999-2009
Web19 | Advertise on the Code Project