greenmail java_javamail – FloderClosedException while retrieving from dummy green mail imap server

  • Post author:
  • Post category:java


I have created a dummy green mail server to simulate a mailbox for my application. My application basically connects to a mail server and retrieves new mails based on some criteria. So i have created a dummy mail server for my application using green mail. Now when I start my green mail and afterwards when try to connect to the mailbox created by green mail by my original application(application under test) then the application is able to connect to it and able to read list of new mails from the green mail server but when i try to read parameters of the fetched then it says-:

javax.mail.FolderClosedException: * BYE JavaMail Exception: java.io.IOException: Connection dropped by server?

at com.sun.mail.imap.IMAPMessage.loadEnvelope(IMAPMessage.java:1428)

at com.sun.mail.imap.IMAPMessage.getSubject(IMAPMessage.java:427)

at greenmailtest.ImapIT.getMails(ImapIT.java:79)

at greenmailtest.ImapIT.main(ImapIT.java:94)

I am attaching my test code here:-

public void setUp() {

mailServer = new GreenMail(ServerSetupTest.IMAP);

mailServer.start();

}

public void tearDown() {

mailServer.stop();

}

public void getMails() throws IOException, MessagingException,

UserException, InterruptedException {

// create user on mail server

GreenMailUser user = mailServer.setUser(EMAIL_USER_ADDRESS, USER_NAME,

USER_PASSWORD);

// create an e-mail message using javax.mail ..

File file=new File(“/home/sameepsinghania/Desktop/HDFC/Addcalbackfailure.png”);

// byte[] byteArray=TestMailUtil.readContentIntoByteArray(file);

MimeMultipart multipart=TestMailUtil.createMultipartWithAttachment(EMAIL_TEXT,file, “sameep.png”);

MimeMessage message = new MimeMessage((Session) null);

message.setFrom(new InternetAddress(EMAIL_TO));

message.addRecipient(Message.RecipientType.TO, new InternetAddress(

EMAIL_USER_ADDRESS));

message.setSubject(EMAIL_SUBJECT);

message.setContent(multipart);

// use greenmail to store the message

user.deliver(message);

Properties props = new Properties();

Session session = Session.getInstance(props);

URLName urlName = new URLName(“imaps”, “127.0.0.1”,

ServerSetupTest.IMAP.getPort(), null, user.getLogin(),

user.getPassword());

Store store = session.getStore(urlName);

store.connect();

Folder folder = store.getFolder(“INBOX”);

folder.open(Folder.READ_ONLY);

Message[] messages = folder.getMessages();

for(Message message1: messages){

System.out.println(“subject “+message1.getSubject());//**this is the line where I get the exception**

}

}

JavaMail Debug logs-:

DEBUG: setDebug: JavaMail version 1.5.3

DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle]

DEBUG IMAP: mail.imap.fetchsize: 16384

DEBUG IMAP: mail.imap.ignorebodystructuresize: false

DEBUG IMAP: mail.imap.statuscachetimeout: 1000

DEBUG IMAP: mail.imap.appendbuffersize: -1

DEBUG IMAP: mail.imap.minidletime: 10

DEBUG IMAP: closeFoldersOnStoreFailure

DEBUG IMAP: trying to connect to host “127.0.0.1”, port 3143, isSSL false

* OK IMAP4rev1 Server GreenMail ready

A0 CAPABILITY

* CAPABILITY IMAP4rev1 LITERAL+ QUOTA

A0 OK CAPABILITY completed.

DEBUG IMAP: protocolConnect login, host=127.0.0.1, user=hascode, password=

DEBUG IMAP: LOGIN command trace suppressed

DEBUG IMAP: LOGIN command result: A1 OK LOGIN completed.

A2 CAPABILITY

* CAPABILITY IMAP4rev1 LITERAL+ QUOTA

A2 OK CAPABILITY completed.

DEBUG IMAP: connection available — size: 1

A3 EXAMINE INBOX

* FLAGS (\Answers

ed \Deleted \Draft \Flagged \Seen)

* 1 EXISTS

* 1 RECENT

* OK [UIDVALIDITY 1461648432354]

* OK [UNSEEN 1] Message 1 is the first unseen

* OK [PERMANENTFLAGS (\Answers

ed \Deleted \Draft \Flagged \Seen)]

A3 OK [READ-ONLY] EXAMINE completed.

A4 FETCH 1 (ENVELOPE INTERNALDATE RFC822.SIZE)

javax.mail.FolderClosedException: * BYE JavaMail Exception: java.io.IOException: Connection dropped by server?

at com.sun.mail.imap.IMAPMessage.loadEnvelope(IMAPMessage.java:1428)

at com.sun.mail.imap.IMAPMessage.getSubject(IMAPMessage.java:427)

at greenmailtest.ImapIT.getMails(ImapIT.java:78)



版权声明:本文为weixin_42420393原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。