javamail - Java ClassCastException in reading Gmail mails -


i want read gmail inbox mail using "imps". i'm using code read mail. here sender name, date, subject , content. see code below:

import java.util.*; import javax.mail.*;  public class readingemail { public static void main(string[] args) {     properties props = new properties();     props.setproperty("mail.store.protocol", "imaps");     try {         session session = session.getinstance(props, null);         store store = session.getstore();         store.connect("imap.gmail.com", "mail", "pass");         folder inbox = store.getfolder("inbox");         inbox.open(folder.read_only);         message msg = inbox.getmessage(inbox.getmessagecount());         address[] in = msg.getfrom();         (address address : in) {             system.out.println("from:" + address.tostring());         }         multipart mp = (multipart) msg.getcontent();         bodypart bp = mp.getbodypart(0);         system.out.println("sent date:" + msg.getsentdate());         system.out.println("subject:" + msg.getsubject());         system.out.println("content:" + bp.getcontent());     } catch (exception mex) {         mex.printstacktrace();     } } } 

this code working before 3-4 days. run code , error:

java.lang.classcastexception: java.lang.string cannot cast javax.mail.multipart @ pkg.readingemail.main(readingemail.java:21) 

this code of line 21:

multipart mp = (multipart) msg.getcontent(); 

please me can solve exception thank :)


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -