我创建了一个虚拟绿色邮件服务器来模拟我的应用程序的邮箱。 我的应用程序基本上连接到邮件服务器并根据某些条件检索新邮件。所以我使用绿色邮件为我的应用程序创建了一个虚拟邮件服务器。 现在,当我启动绿色邮件时,之后当我尝试通过我的原始应用程序(正在测试的应用程序)连接到绿色邮件创建的邮箱时,应用程序能够连接到它并能够从绿色邮件中读取新邮件列表服务器,但当我尝试读取所提取的参数然后它说 - :
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)
我在这里附上我的测试代码: -
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=<non-null>
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 (\Answered \Deleted \Draft \Flagged \Seen)
* 1 EXISTS
* 1 RECENT
* OK [UIDVALIDITY 1461648432354]
* OK [UNSEEN 1] Message 1 is the first unseen
* OK [PERMANENTFLAGS (\Answered \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)