저는 내 이메일을 다운로드하는 데 사용하는 Java 클라이언트 응용 프로그램을 개발했습니다. 전자 메일에서 일부 첨부 파일, 특히 인증 된 회사에 전자 메일을 보낼 때 영수증으로받은 XML 파일을 찾을 수 없다는 사실을 알았습니다. 나는 다운로드 첨부 파일에 사용하는 코드 :JavaMail에서 XML 첨부 파일을 읽을 수 없습니다.
private void getAttachment(Message message) throws Exception {
Multipart multipart = (Multipart) message.getContent();
for (int i = 0; i < multipart.getCount(); i++) {
BodyPart bodyPart = multipart.getBodyPart(i);
if (!Part.ATTACHMENT.equalsIgnoreCase(bodyPart.getDisposition())
&& StringUtils.isEmpty(bodyPart.getFileName())) {
continue; // dealing with attachments only
}
InputStream is = bodyPart.getInputStream();
File f = new File("tmp/" + bodyPart.getFileName());
FileOutputStream fos = new FileOutputStream(f);
byte[] buf = new byte[4096];
int bytesRead;
while ((bytesRead = is.read(buf)) != -1) {
fos.write(buf, 0, bytesRead);
}
fos.close();
}
}
내 질문은이 : XML 첨부 파일을 다운로드에 어떤 제한이 있습니까? 또는 Message 클래스의 다른 메소드에 대해 사용해야합니까? 감사합니다
다른 첨부 파일 형식을 사용할 수 있습니까? 'if' 부분을 없애면 어떻게 될까요? – Hichamov
예 다른 첨부 파일을 읽을 수 있습니다. if 부분을 제거하면 메일 본문이 텍스트로 다운로드됩니다. – user2824073