4

I want to change synchronously change in email application then automatic change in server email. For example, I have read the unread message on email application then automatic server email change unread mail to read mail.

My email application has use mail jar file, activation.jar and additional jar file use and following code are use for connectivity email application to server email:

Properties props = System.getProperties();
            props.setProperty("mail.store.protocol", "imaps");
            props.put("mail.smtp.starttls.enable","true");
            Authenticator auth = new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication(){
                    return new PasswordAuthentication("USEREMAILID","PASSWORD ");
                    }
            };
            sessioned= Session.getDefaultInstance(props, auth);
            store = sessioned.getStore("imaps");
           store.connect("smtp.gmail.com","USEREMAILID","PASSWORD ");
             inbox = store.getFolder("inbox");
            inbox.open(Folder.READ_ONLY);
            FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
            UNReadmessages = inbox.search(ft);
halfer
  • 19,824
  • 17
  • 99
  • 186
Akash Singh
  • 5,171
  • 2
  • 26
  • 55
  • Can you write your entire source code that handle synchronization proses between server and local drive that you save your email on local. –  Apr 26 '12 at 11:34

2 Answers2

4

I have solved the issue.
Never close the connection on run time, with below code.

   inbox.open(Folder.READ_WRITE);
Jubin Patel
  • 1,959
  • 19
  • 38
Akash Singh
  • 5,171
  • 2
  • 26
  • 55
2

If you're doing this while "online", with the Store connected and the Folder open, changes you make through the JavaMail API are immediately reflected on the server. It's up you and your program logic to ensure that (for example) your user interface action that marks a message read or unread results in a corresponding JavaMail operation.

Note also, for "read" in particular, fetching the message content will cause the server to mark the message as read, without any other explicit action needed on your part.

If you want all this to happen when the application is "offline", and resynchronize when you're next online, that's much harder. The JavaMail FAQ has some pointers to help with that.

Bill Shannon
  • 29,579
  • 6
  • 38
  • 40