Aspose.Email에서 메시지의 포함된 이메일 첨부 파일 읽기
Contents
[
Hide
]
Aspose.Email - 메시지에서 내장 이메일 첨부 파일 읽기
때때로 이메일에 다른 이메일이 첨부 파일 형태로 내장된 경우가 있습니다. 이러한 내장된 이메일은 자체 수신자 목록, 제목, 본문 및 첨부 파일까지 포함한 완전한 메시지입니다. 이러한 메시지마다 또 다른 내장 메시지를 포함할 수 있습니다. Aspose.Email Java를 사용하면 개발자는 각 내장 메시지에 개별 메시지처럼 접근할 수 있습니다. 이 예제는 재귀 기능을 사용하는 방법을 보여줍니다.
Java
MailMessage message = MailMessage.load(dataDir + \"embedded.msg\", MessageFormat.getMsg());
for (int i = 0; i < message.getAttachments().size(); i++)
{
Attachment att = (Attachment) message.getAttachments().get_Item(i);
System.out.println("Attachment Name: " + att.getName());
// Get the name of attachment. If msg subject contains characters like :, /, \ etc., replace with space
// because windows cannot save files with these characters
// also save first 50 characters as file name to avoid long file names
String attFileName = att.getName().replace(".eml", "").replace(":", " ").replace("\\", " ").replace("/", " ").replace("?", "");
if (attFileName.length() > 50)
{
attFileName = attFileName.substring(0, 50);
}
String attExt = (att.getName().substring(att.getName().lastIndexOf("."), att.getName().lastIndexOf(".") + 4));
// Save the attachment to disk
att.save(dataPath + attFileName + attExt);
// Check if it is an orphaned text attachment file (ATT00001.txt....) and of type eml
if ((attExt.equals(".eml")) || (att.getContentType().getMediaType().equals("text/plain") && att.getName().contains(".txt") == true && att.getName().contains("ATT") == true))
{
// Try to load this text file in MailMessage
MailMessage attMsg = MailMessage.load(dataPath + attFileName + attExt, MessageFormat.getEml());
// Call the function recursively to parse this message and attachments
ParseMessage(attMsg);
}
}실행 코드 다운로드
샘플 코드 다운로드
자세한 내용은 방문하십시오 메시지에서 내장 이메일 첨부 파일 읽기.