I have written java code using java mail API. Which does the following things for IMAPs account:
- Mark mail as read/Unread.
- Send/Delete mails.
My code works well for most of IMAP mail accounts. I am fetching the mails based on their UID. But surprisingly it isn't working for the delete operation for the mail accounts having domain xxx12@yahoo.co.jp. I also tried creating a new account having @yahoo.co.jp in the domain.
The things which are working for mail accounts having @yahoo.co.jp are:
- Mark as read/Unread.
So far i have tried this link Delete Email on Server using javax.mail and read https://javaee.github.io/javamail/FAQ . I have also tried delete operation with other yahoo mails(i.e xxx12@yahoo.com) along with gmail mail account in which the below code works as expected, both the types that were tested were of IMAP type.
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
props.put("mail.smtp.starttls.enable", true);
session = Session.getInstance(props, null);
session.setDebug(true);
store = session.getStore("imaps");
store.connect("host", "port","uname","pass");
inbox = (IMAPFolder) store.getFolder(folderName);
inbox.open(Folder.READ_WRITE);
long uid = Long.parseLong(messageId);
message = inbox.getMessageByUID(uid);
if (message != null) {
if(form.getFlagType().equals("read")){
Flags read = new Flags(Flags.Flag.SEEN);
message.setFlags(read, true);
} else if(form.getFlagType().equals("unread")){
Flags unread = new Flags(Flags.Flag.SEEN);
message.setFlags(unread, false);
} else if(form.getFlagType().equals("delete")){
Flags deleteMail = new Flags(Flags.Flag.DELETED);
message.setFlags(deleteMail, true);
}
}
inbox.close(true);
catch(Exception e){
e.printStackTrace();
}
The line written in above code message.setFlags(deleteMail, true);
Gives an exception as show below:
javax.mail.MessagingException:
A4 NO [CANNOT] STORE It's not possible to perform specified operation;
nested exception is:
com.sun.mail.iap.CommandFailedException: A4 NO [CANNOT] STORE It's not possible to perform specified operation
I want to delete mails having yahoo.co.jp as their domain. Any help would be greatly appreciated.
UPDATE:
After adding the session.setDebug(true);
I found the following:
A2 SELECT INBOX
* 3 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1557837307] UIDs valid
* OK [UIDNEXT 20006] Predicted next UID
* FLAGS (\Answered \Deleted \Draft \Flagged \Seen $Forwarded $Junk $NotJunk)
* OK [PERMANENTFLAGS (\Answered \Deleted \Draft \Flagged \Seen $Forwarded $Junk $NotJunk)] Permanent flags
* OK [HIGHESTMODSEQ 27]
A2 OK [READ-WRITE] SELECT completed; now in selected state
A3 UID FETCH 20005 (UID)
* 3 FETCH (UID 20005)
A3 OK UID FETCH completed
A4 STORE 3 +FLAGS (\Deleted)
A4 NO [CANNOT] STORE It's not possible to perform specified operation
DEBUG IMAPS: IMAPProtocol noop
A5 NOOP
A5 OK NOOP completed
A6 CLOSE
A6 OK CLOSE completed
DEBUG IMAPS: added an Authenticated connection -- size: 1
DEBUG IMAPS: IMAPProtocol noop
A7 NOOP
A7 OK NOOP completed
A8 LOGOUT
* BYE IMAP4rev1 Server logging out
A8 OK LOGOUT completed
DEBUG IMAPS: IMAPStore connection dead
DEBUG IMAPS: IMAPStore cleanup, force false
DEBUG IMAPS: IMAPStore cleanup done
Please ask if you need any further details on the question.