Email's and Feeders

I really think I have come a long way on learning JAVA and I am beginning to fall in love with AJAX deeper than I ever think of especially when I manage to run two of the most important aspect in web technology. Email and RSS Feeders.

I have been reading pinoytechscene website for the longest time and since the beginning I was really amaze at how the owner manage to get the feeds of its members and be able to show it to its readers. I have long for that technology for the longest time I guess I just did not have the time and the right technology in my hands in order to build it. Web apps simply won't appeal on me.

Not until Google Web Toolkit came along. It was the kind of technology that I really want in a web. It's so perfect for me that I would really dive in to learn anything just to make all those web technology (that I used to hate) be able to run.

The OpenSource movement was the real key why I manage to make this happen. They help me learn the cool things that I could only imagine by posting their code in order to keep the fire burning to those who are passionate with coding.

I decided to contribute in order to help those developers like me who are in search of solution to their problems.

Email- I use JavaMail in order to connect and communicate to websites that support POP3(Post office Protocol) or IMAP(Internet Messaging Access Protocol) like Gmail or Yahoo mail.

Here's my code:

public void receiveEmail(String popServer, String popUser, String popPassword){
Store store=null;
Folder folder=null;
try{
// -- Get hold of the default session --
Properties props = System.getProperties();
Session session = Session.getDefaultInstance(props, null);
// -- Get hold of a IMAP/POP3 message store, and connect to it --
store = session.getStore("imaps");
store.connect(popServer, popUser, popPassword);
// -- Try to get hold of the default folder --
folder = store.getDefaultFolder();
if (folder == null) throw new Exception("No default folder");
// -- ...and its INBOX --
folder = folder.getFolder("INBOX");
if (folder == null) throw new Exception("No POP3/IMAP INBOX");
// -- Open the folder for read only --
folder.open(Folder.READ_ONLY);
// -- Get the message wrappers and process them --
Message[] msgs = folder.getMessages();
for (int msgNum = 0; msgNum <>
{
System.out.println(msgs[msgNum]);
}

}catch(Exception e){
System.out.println(e.getMessage());

}
//closing the assign fields
finally{
try{
if (folder!=null) folder.close(false);
if (store!=null) store.close();

}catch(Exception e){
System.out.println(e.getMessage());
}

// -- Close down nicely --

}

}

RSS Reader- To get those feeds from anysite that support all popular RSS or Atom link I use Rome.

Here's my code:

public String getSyndFeed(String url) {
String feeds = null;
try {
URL syndURL = new URL(url);
SyndFeedInput syndInput = new SyndFeedInput();
SyndFeed syndFeed = syndInput.build(new XmlReader(syndURL));

int listSize = syndFeed.getEntries().size();

//stores to iterator to act like recrods where you can move back or next

Iterator iter = syndFeed.getEntries().iterator();
Iterator iterLink = syndFeed.getEntries().iterator();
Iterator iterTitle = syndFeed.getEntries().iterator();
Iterator iterDescription = syndFeed.getEntries().iterator();


listSize = (listSize > 10) ? 10 : listSize;
StringBuffer theLink = new StringBuffer();


for (int i = 0; i <>
SyndEntry entry = (SyndEntry)iter.next();

if (entry.getDescription()!=null){
theLink.append("").append(((SyndEntry)iterTitle.next()).getTitle().toString()).append("

").append(((SyndEntry)iterDescription.next()).getDescription().getValue().toString());

}else{
theLink.append("").append(((SyndEntry)iterTitle.next()).getTitle().toString()).append("

").append("");

}
}

feeds=theLink.toString();

} catch (Exception e) {
System.out.println(e.getMessage());

}

return feeds;
}

I am still working on my site. Soon I will be glad to show you the results that I built.

Comments

sabir said…
This comment has been removed by the author.

Popular posts from this blog

Apple's Edge Over Microsoft?

High Grounds Cafe - Best Internet Cafe in the Philippines

John Gokongwei Speech before Ateneo 2004 Graduates