How do I use the JavaMail API to send newsgroups m...
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Francesco_marchioni
Posted On:   Thursday, July 20, 2000 07:26 PM

How do I use the JavaMail API to send newsgroups messages?

Re: How do I use the JavaMail API to send newsgroups m...

Posted By:   John_Zukowski  
Posted On:   Monday, April 2, 2001 09:47 AM

You need to get an NNTP provider, like Knife's. You must manually create an instance of their NNTP Transport object to send the message as well as specify the newsgroup to post to.


The following program does just that.


import javax.mail.*;
import javax.mail.internet.*;

public class PutNewsExample {
public static void main (String args[]) throws Exception {
String host = args[0];
String from = args[1];
String newsgroup = args[2];
String username = args[3];
String password = args[4];

// Get session
Session session = Session.getInstance(
System.getProperties(), null);

// Define message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setSubject("Test Test - Ignore");
message.setText("Will this work?");
message.addHeader("Newsgroups", newsgroup);

// Define transport
Transport transport =
new dog.mail.nntp.NNTPTransport(session,
new URLName("news:" + newsgroup));

transport.connect(host, username, password);
transport.sendMessage(message, message.getAllRecipients());

transport.close();

}
}
About | Sitemap | Contact