Tutorial 3: Posting to a Newsgroup
Overview | Properties | Methods
The following source code demonstrates how to post an article to a specified news group at a news server.
We create an instance of the Dundas
Mailer Control, set the FromAddress
property (used as the ReplyTo
address if there are no Address objects in the ReplyTOs
collection) and then set the Body property
which constitutes
the article body. For this demonstration we will post an article in reply
to an existing article which we read. To
post our article underneath an existing article (as opposed to posting
to the root directory) we will add a custom
header named "References" to the Mailer control's CustomHeaders
collection, and set its value to the ID of the article
we are responding to.
<%
Dim objEmail 'stores instance of Mailer object
'PostArticle throws an exception if it is not successful so we use
' inline error trapping with an On Error Resume Next statement
On Error Resume Next
'create instance of Mailer control
Set objEmail = Server.CreateObject("Dundas.Mailer")
'specify an SMTP server to increase the speed and reliability of the operation
objEmail.SMTPRelayServers.Add "SomeSmtpServer.com"
'set the subject of the article
objEmail.Subject = "This is the article subject."
'add a custom header named "References" to the CustomHeaders collection, setting
' the value of the header to the ID of the article to post beneath (respond to)
objEmail.CustomHeaders.Add "References", "TheArticleID"
'set the body of the article
objEmail.Body = "This is the body of the article."
'set the FromAddress (This is used as the ReplyTo address if are no Address
' objects in the ReplyTOs collection)
objEmail.FromAddress = "[email protected]"
'now attempt to post the article (we will use a public Microsoft news group here)
objEmail.PostArticle "msnews.microsoft.com","microsoft.a.test"
'now trap for success/failure of the article posting
If Err.Number <> 0 Then
'PostArticle failed.
Response.Write "The following error occurred: " & Err.Description
Else
'PostArticle succeeded
Response.Write "The article was successfully posted."
End If
Set objEmail = Nothing
%>