Issues with gmail: popping only once and delete not working
Hi,
i m using Javamail for sending/recieving email from gmail.
1) The problem is that the following code only fetches all the Emails from gmail only once. To pop the nwe emails that has arrived i have to go to the gmail settings again and change the Forward/Pop settings to "Enable POP for all mail (even mail that's already been downloaded)". But again it pops all the emails only once.
2) The second problem is i am trying to remove emails i have popped out by marking them DELETE and closing the folder but that does not delete the messages , Even though the debug messages show + MARK DELETED
Any help is most welcome.....
Code:
Properties props =new Properties();
Store store;
boolean isSSL=true;
String popPort="995";
String popServer="pop.gmail.com";
String popUser="username";
String popPassword="password";
/*boolean isSSL=false;
String popPort="110";
String popServer="mail.bluebottle.com";
String popUser="teraleapggn@bluebottle.com";
String popPassword="stypher";*/
if(isSSL)
props.setProperty("mail.pop3.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.pop3.socketFactory.fallback","false");
props.setProperty("mail.pop3.port", popPort);
props.setProperty("mail.pop3.socketFactory.port", popPort);
//props.setProperty("mail.pop3.rsetbeforequit", "true");
props.setProperty("mail.debug","true");
Session session = Session.getInstance(props);
try{
store = session.getStore("pop3");
System.out.println("going to connect");
store.connect(popServer, popUser, popPassword);
System.out.println("connected");
Folder folder = store.getDefaultFolder();
if (folder ==null)
thrownew Exception("No default folder");
folder = folder.getFolder ("INBOX");
if (folder ==null)
{
thrownew Exception("No POP3 INBOX");
}
System.out.println("going to open folder");
folder.open(Folder.READ_WRITE);
System.out.println("folder opened");
Message[] msgs = folder.getMessages();
System.out.println("got messages"+msgs.length);
for(int i=msgs.length-1; i>=0; i--)
{
//System.out.println("UID==========="+iqMsg.UID);
//for(int indx=0;indx<olUids.size();indx++)
//System.out.println("olUID========="+olUids.get(indx));
//System.out.println("removing");
System.out.println(i);
msgs[i].setFlag(Flags.Flag.DELETED,true);//can not be deleted if it is signed in somwhere
//msgs[i].setFlag(Flags.Flag.SEEN, true);
if (msgs[i].isSet(Flags.Flag.DELETED))
System.out.println("DELETED message");
//msgs[i].saveChanges();
}
folder.close(true);
store.close();
}catch (NoSuchProviderException e){
e.printStackTrace();
}catch (MessagingException e){
e.printStackTrace();
}catch (Exception e){
e.printStackTrace();
}
System.out.println("its done now");
The debug messages are as follows
__
(First time)
DEBUG: JavaMail version 1.4ea
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jre1.5.0_05\lib\javamail.providers (The system cannot find the file specified)
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.providers
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.address.map
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jre1.5.0_05\lib\javamail.address.map (The system cannot find the file specified)
DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]
going to connect
DEBUG POP3: connecting to host "pop.gmail.com", port 995, isSSL false
S: +OK Gpop ready for requests from 124.7.66.42 38pf5903707nzk
C: USER username
S: +OK send PASS
C: PASS password
S: +OK Welcome.
connected
going to open folder
C: STAT
S: +OK 21 47069
folder opened
C: NOOP
S: +OK
got messages21
20
DELETED message
19
DELETED message
18
DELETED message
17
DELETED message
16
DELETED message
15
DELETED message
14
DELETED message
13
DELETED message
12
DELETED message
11
DELETED message
10
DELETED message
9
DELETED message
8
DELETED message
7
DELETED message
6
DELETED message
5
DELETED message
4
DELETED message
3
DELETED message
2
DELETED message
1
DELETED message
0
DELETED message
C: DELE 1
S: +OK marked for deletion
C: DELE 2
S: +OK marked for deletion
C: DELE 3
S: +OK marked for deletion
C: DELE 4
S: +OK marked for deletion
C: DELE 5
S: +OK marked for deletion
C: DELE 6
S: +OK marked for deletion
C: DELE 7
S: +OK marked for deletion
C: DELE 8
S: +OK marked for deletion
C: DELE 9
S: +OK marked for deletion
C: DELE 10
S: +OK marked for deletion
C: DELE 11
S: +OK marked for deletion
C: DELE 12
S: +OK marked for deletion
C: DELE 13
S: +OK marked for deletion
C: DELE 14
S: +OK marked for deletion
C: DELE 15
S: +OK marked for deletion
C: DELE 16
S: +OK marked for deletion
C: DELE 17
S: +OK marked for deletion
C: DELE 18
S: +OK marked for deletion
C: DELE 19
S: +OK marked for deletion
C: DELE 20
S: +OK marked for deletion
C: DELE 21
S: +OK marked for deletion
C: QUIT
S: +OK Farewell.
its done now
(after first time):
DEBUG: JavaMail version 1.4ea
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jre1.5.0_05\lib\javamail.providers (The system cannot find the file specified)
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.providers
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.address.map
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\jre1.5.0_05\lib\javamail.address.map (The system cannot find the file specified)
DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]
going to connect
DEBUG POP3: connecting to host "pop.gmail.com", port 995, isSSL false
S: +OK Gpop ready for requests from 124.7.66.42 f51pf9973165pyh
C: USER username
S: +OK send PASS
C: PASS password
S: +OK Welcome.
connected
going to open folder
C: STAT
S: +OK 0 0
folder opened
C: NOOP
S: +OK
got messages0
C: QUIT
S: +OK Farewell.
its done now>

