Click here to Skip to main content
Click here to Skip to main content

Posting newsgroup messages with NNTP using Indy

, 24 Jul 2005
Rate this:
Please Sign up or sign in to vote.
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

Share

About the Author

Chad Z. Hower, a.k.a. Kudzu
"Programming is an art form that fights back"
www.KudzuWorld.com
 
Formerly the Regional Developer Adviser (DPE) for Microsoft Middle East and Africa, he was responsible for 85 countries spanning 4 continents and 10 time zones. Now Chad is a Microsoft MVP.
 
Chad is the chair of several popular open source projects including Indy and Cosmos (C# Open Source Managed Operating System).
 
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. Chad has visited more than 60 countries, visiting most of them several times.

Comments and Discussions

 
General[Message Deleted] Pinmemberit.ragester2-Apr-09 21:58 
GeneralMisleading Article Title PinmemberAshaman26-Jul-05 3:35 
GeneralRe: Misleading Article Title PinmemberMartin Robins28-Jul-05 8:32 
GeneralRe: Misleading Article Title Pinmemberundeclared12-Jul-08 8:56 
GeneralCool PinmemberSuper Lloyd24-Jul-05 17:31 

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.

| Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 24 Jul 2005
Article Copyright 2005 by Chad Z. Hower aka Kudzu
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid