![]() |
General Programming »
Internet / Network »
Internet & Network
Intermediate
Posting newsgroup messages with NNTP using IndyBy Chad Z. Hower aka KudzuIn 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
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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.
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();
}
}
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.
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.
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.
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.
| You must Sign In to use this message board. | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
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 Web20 | Advertise on the Code Project |