Click here to Skip to main content
14,935,153 members
Articles / Programming Languages / C#
Article
Posted 24 Jul 2005

Stats

43.1K views
250 downloads
12 bookmarked

Posting newsgroup messages with NNTP using Indy

Rate me:
Please Sign up or sign in to vote.
2.63/5 (10 votes)
24 Jul 20051 min read
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

C#
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

Share

About the Author

Chad Z. Hower, a.k.a. Kudzu
"Programming is an art form that fights back"

I am a former Microsoft Regional DPE (MEA) covering 85 countries, former Microsoft Regional Director, and 10 Year Microsoft MVP.

I have lived in Bulgaria, Canada, Cyprus, Switzerland, France, Jordan, Russia, Turkey, The Caribbean, and USA.

Creator of Indy, IntraWeb, COSMOS, X#, CrossTalk, and more.

Comments and Discussions

 
General[Message Deleted] Pin
it.ragester2-Apr-09 21:58
Memberit.ragester2-Apr-09 21:58 
GeneralMisleading Article Title Pin
Ashaman26-Jul-05 3:35
MemberAshaman26-Jul-05 3:35 
GeneralRe: Misleading Article Title Pin
Martin Robins28-Jul-05 8:32
professionalMartin Robins28-Jul-05 8:32 
GeneralRe: Misleading Article Title Pin
undeclared12-Jul-08 8:56
Memberundeclared12-Jul-08 8:56 
GeneralCool Pin
Super Lloyd24-Jul-05 17:31
MemberSuper Lloyd24-Jul-05 17:31 

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

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