JavaMail API를 사용하여 메일 발송자 메시지에 액세스하려고합니다.JavaMail을 사용하여 Mailinator POP3에 액세스
서버에 제대로 연결할 수 있지만 메시지를 읽는 중 "폴더가 열려 있지 않음"예외가 계속 발생하며 폴더가 열려 있는지 확인하고 폴더를 열지 않으면 그다지 열리지 않습니다. 도움도. 나는 우편물 발송자가 연결을 끝내는 어떤 이유로 또는 이렇게 추측한다.
getContent를 사용하는 대신 메시지의 inputstream을 가져 오려고하면 inputstream에서 읽을 수 있으며 메시지 등의 스타일링을 포함하지만 어떤 이유로 입력 스트림에서 읽은 데이터가 메시지를 포함하지 않는 것처럼 보입니다 본문 ...
mailinator에 관한 것이거나 pop3 또는 다른 쉽게 읽을 수있는 다른 임의의 전자 메일 읽기 서비스를 제공 할 수 있다면이 프로젝트에서 mailinator를 사용하면 별 문제가되지 않습니다.
내 현재 메일 읽기 코드.
private void checkMail(String user) {
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
try {
Store store = session.getStore("pop3");
store.connect("pop.mailinator.com", 110, user, "12345678");
Folder inbox = store.getFolder("inbox");
if(inbox == null) {
System.out.println("no inbox");
} else {
inbox.open(Folder.READ_ONLY);
for(Message message: inbox.getMessages()) {
byte[] buffer = new byte[10000];
int read = 0;
try {
while((read = message.getInputStream().read(buffer, 0, 1024)) > 0) {
for(int i = 0; i < buffer.length; i++) {
System.out.print((char)buffer[i]);
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*try {
System.out.println(message.getContent().toString());
} catch (IOException e) {
e.printStackTrace();
}*/
}
}
inbox.close(false);
store.close();
} catch (NoSuchProviderException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
또한 inputstream에서 읽을 때 입력 스트림이 끝나지 않는 것처럼 보입니다. 처음부터 다시 시작합니다. 제 목적은 메시지 본문과 주제를 얻는 것입니다.