Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-30-2007, 06:15 PM
Member
 
Join Date: Jul 2007
Posts: 4
consult4u is on a distinguished road
Access Email usind a java mail client Access Email usind a java mail client
Hello,
I am trying to use this sample code below to access my mail keep gene rating errors..

Can anyone help me if there is any problem with the code....It says all the packages does not exist and could not find symbol class messge, class store and so on...

Code:
package com.devx.jmail; import javax.mail.*; import javax.mail.internet.*; import java.util.*; import java.io.*; import net.sf.classifier4J.*; import net.sf.classifier4J.bayesian.*; import net.sf.classifier4J.summariser.*; public class MailReader { public static void main(String[] args) { try { String popServer="any"; String popUser="any"; String popPassword="any"; GetMail(popServer, popUser, popPassword); } catch (Exception e) { e.printStackTrace(); } System.exit(0); } public static void GetMail(String popServer, String popUser, String popPassword) { Store store=null; Folder folder=null; String strEmail = ""; double dSpamScore = 0.0; try { Properties props = System.getProperties(); Session session = Session.getDefaultInstance(props, null); store = session.getStore("pop3"); store.connect(popServer, popUser, popPassword); folder = store.getDefaultFolder(); if (folder == null) throw new Exception("No default folder"); folder = folder.getFolder("INBOX"); if (folder == null) throw new Exception("No POP3 INBOX"); folder.open(Folder.READ_ONLY); Message[] msgs = folder.getMessages(); for (int nMsg = 0; nMsg < msgs.length; nMsg++) { strEmail = buildMessage(msgs[nMsg]); String strSumm = getSummary(strEmail,3); System.out.println(strSumm); dSpamScore = checkSpam(strEmail); //dSpamScore = checkSpamWithBayes(strEmail); if(dSpamScore > 0.7) { System.out.println("--------------------------"); System.out.println("SPAM DETECTED:"); System.out.println("--------------------------"); System.out.println(strEmail); System.out.println("--------------------------"); } } } catch (Exception e) { e.printStackTrace(); } finally { try { if (folder!=null) folder.close(false); if (store!=null) store.close(); } catch (Exception e2) { e2.printStackTrace(); } } } public static String buildMessage(Message message) { String strReturn = ""; try { String from=((InternetAddress)message.getFrom()[0]).getPersonal(); if (from==null) from=((InternetAddress)message.getFrom()[0]).getAddress(); strReturn += "FROM: " + from; String subject=message.getSubject(); strReturn += "SUBJECT: "+subject; Part messagePart=message; Object content=messagePart.getContent(); if (content instanceof Multipart) { messagePart=((Multipart)content).getBodyPart(0); strReturn += "[ Multipart Message ]"; } String contentType=messagePart.getContentType(); strReturn += "CONTENT:"+contentType; if (contentType.startsWith("text/plain")|| contentType.startsWith("text/html")) { InputStream is = messagePart.getInputStream(); BufferedReader reader=new BufferedReader(new InputStreamReader(is)); String thisLine=reader.readLine(); while (thisLine!=null) { strReturn +=thisLine; thisLine=reader.readLine(); } } } catch (Exception ex) { ex.printStackTrace(); } return strReturn; } public static double checkSpam(String strEmailBody) { double dClassification = 0.0; try { SimpleClassifier classifier = new SimpleClassifier(); classifier.setSearchWord( "activity" ); dClassification = classifier.classify(strEmailBody); } catch(Exception e) { e.printStackTrace(); } return dClassification; } public static double checkSpamWithBayes(String strEmailBody) { double dReturn = 0.0; try { IWordsDataSource wds = new SimpleWordsDataSource(); wds.addMatch("activity"); wds.addMatch("transactions"); wds.addMatch("Devx"); IClassifier classifier = new BayesianClassifier(wds); dReturn = classifier.classify(strEmailBody); } catch(Exception e) { e.printStackTrace(); } return dReturn; } public static String getSummary(String strEmailBody, int nSentences) { ISummariser summ = new SimpleSummariser(); String strSumm = summ.summarise(strEmailBody,nSentences); return strSumm; } }
Also, in what way can I group the emails based on users activities not folder using the code above and also summarrised each mails.

Please put me through.

Thanks alot.

Last edited by levent : 07-30-2007 at 08:20 PM. Reason: Code placed inside [code] tags.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-30-2007, 08:22 PM
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
You should download Java Mail library and put its jar files into your classpath. Java Mail API is not included in Java Standard Library!

By the way, next time please place your code inside [code] tags with proper indentation. That will be easier to read and follow.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-31-2007, 09:29 AM
Member
 
Join Date: Jul 2007
Posts: 4
consult4u is on a distinguished road
I have set the CLASSPATH to:

set CLASSPATH=%CLASSPATH%;c:\download\javamail-1.4\mail.jar; and also
set CLASSPATH=%CLASSPATH%;c:\download\activation\activ ation.jar

But these are the errors again:




C:\CODES\javamail-1.4\demo>javac MailReader.java
MailReader.java:2: package javax.mail does not exist
import javax.mail.*;
^
MailReader.java:3: package javax.mail.internet does not exist
import javax.mail.internet.*;
^
MailReader.java:6: package net.sf.classifier4J does not exist
import net.sf.classifier4J.*;
^
MailReader.java:7: package net.sf.classifier4J.bayesian does not exist
import net.sf.classifier4J.bayesian.*;
^
MailReader.java:8: package net.sf.classifier4J.summariser does not exist
import net.sf.classifier4J.summariser.*;
^
MailReader.java:78: cannot find symbol
symbol : class Message
location: class com.devx.jmail.MailReader
public static String buildMessage(Message message)
^
MailReader.java:28: cannot find symbol
symbol : class Store
location: class com.devx.jmail.MailReader
Store store=null;
^
MailReader.java:29: cannot find symbol
symbol : class Folder
location: class com.devx.jmail.MailReader
Folder folder=null;
^
MailReader.java:35: cannot find symbol
symbol : class Session
location: class com.devx.jmail.MailReader
Session session = Session.getDefaultInstance(props, null);

So, what else do I need to do or set..........
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
A Client to Send SMTP Mail Java Tip java.net 0 04-07-2008 09:06 PM
Retreiving of mail body using mail number chandu.v09 JavaServer Pages (JSP) and JSTL 0 03-13-2008 03:25 PM
how to create java client to access web services running on https/ssl navneet1083 NetBeans 0 11-13-2007 11:13 AM
Sending a mail with the local mail program thedude Advanced Java 2 07-23-2007 01:19 PM
a problem about java mail client program lunarstyle AWT / Swing 6 06-02-2007 12:43 AM


All times are GMT +3. The time now is 12:58 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org