|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Access Email usind a java mail clientHello,
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... ..................................................................................................................................................... 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. |
|
|
Re: Access Email usind a java mail clientI am trying to use the same piece of sample code, and I also get errors:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at net.sf.classifier4J.bayesian.WordProbability.calculateProbability(WordProbability.java:167) at net.sf.classifier4J.bayesian.WordProbability.setMatchingCount(WordProbability.java:138) at net.sf.classifier4J.bayesian.WordProbability.<init>(WordProbability.java:115) at net.sf.classifier4J.bayesian.SimpleWordsDataSource.addMatch(SimpleWordsDataSource.java:94) at com.devx.jmail.Filters.checkSpamWithBayes(Filters.java:41) at com.devx.jmail.Controller.main(Controller.java:27) This is specifically relating to the bit of code which adds a match to the SimpleWordsDataSource. . . <code> public static double checkSpamWithBayes(String strEmailBody) { double dReturn = 0.0; try { IWordsDataSource wds = new SimpleWordsDataSource(); wds.addMatch("Belgium"); IClassifier classifier = new BayesianClassifier(wds); dReturn = classifier.classify(strEmailBody); } </code> As far as i can tell, the SimpleWordsDataSource does not have any form of persistance; and these words are added at run time. I am unsure what changes I have to make to the code to correct the error. Note: this code is taken from http://www.devx.com/opensource/Article/22019/0/page/3 Any assistance would be much appreciated! Luke |
|
|
Re: Access Email usind a java mail clientThis doesn't have anything to do with JavaMail. You need the
Apache Commons Logging jar file in your CLASSPATH. littlelukey24 wrote: > I am trying to use the same piece of sample code, and I also get errors: > > Exception in thread "main" java.lang.NoClassDefFoundError: > org/apache/commons/logging/LogFactory > at > net.sf.classifier4J.bayesian.WordProbability.calculateProbability(WordProbability.java:167) > at > net.sf.classifier4J.bayesian.WordProbability.setMatchingCount(WordProbability.java:138) > at > net.sf.classifier4J.bayesian.WordProbability.<init>(WordProbability.java:115) > at > net.sf.classifier4J.bayesian.SimpleWordsDataSource.addMatch(SimpleWordsDataSource.java:94) > at com.devx.jmail.Filters.checkSpamWithBayes(Filters.java:41) > at com.devx.jmail.Controller.main(Controller.java:27) > > This is specifically relating to the bit of code which adds a match to the > SimpleWordsDataSource. . . > > <code> > public static double checkSpamWithBayes(String strEmailBody) > { > double dReturn = 0.0; > try > { > IWordsDataSource wds = new SimpleWordsDataSource(); > wds.addMatch("Belgium"); > IClassifier classifier = new BayesianClassifier(wds); > dReturn = classifier.classify(strEmailBody); > } > </code> > > As far as i can tell, the SimpleWordsDataSource does not have any form of > persistance; and these words are added at run time. I am unsure what > changes I have to make to the code to correct the error. > > Note: this code is taken from > http://www.devx.com/opensource/Article/22019/0/page/3 > > Any assistance would be much appreciated! > > Luke > > =========================================================================== To unsubscribe, send email to listserv@... and include in the body of the message "signoff JAVAMAIL-INTEREST". For general help, send email to listserv@... and include in the body of the message "help". |
|
|
Re: Access Email usind a java mail clientHey all,
I have a very simple email client which has been produced display the results of an experimental email filter. . . I was wondering if there is some easy way to detect new messages on a server that need to be downloaded. . . I am thinking setting flags, but is there something more obvious? Many thanks, Luke |
|
|
Re: Access Email usind a java mail clientlittlelukey24 wrote:
> Hey all, > > I have a very simple email client which has been produced display the > results of an experimental email filter. . . > > I was wondering if there is some easy way to detect new messages on a server > that need to be downloaded. . . I am thinking setting flags, but is there > something more obvious? Depends on what you mean by "new", and what protocol you're using. If you're using POP3, see the com.sun.mail.pop3 package javadocs. For IMAP, the RECENT flag marks new messages. Depending on your server and your environment, it may appropriate to keep the folder open and watch for new messages, or it may be better to open the folder occasionally and check for new messages. =========================================================================== To unsubscribe, send email to listserv@... and include in the body of the message "signoff JAVAMAIL-INTEREST". For general help, send email to listserv@... and include in the body of the message "help". |
| Free Forum Powered by Nabble | Forum Help |