Aspose.Email ve Apache POI HSMF kullanarak Mesaj Eklerini Ayıkla
Contents
[
Hide
]
Aspose.Email - Mesaj Eklerini Çıkar
Mevcut mesajlardan ekleri kaydetmek için:
- MailMessage sınıfının bir örneğini oluşturun.
- Doğru MessageFormat’ı belirterek MailMessage sınıfının load() yöntemiyle mevcut e-posta mesajını yükleyin.
- AttachmentCollection sınıfının bir örneğini oluşturun ve MaiMessage örneğinden getAttachments() yöntemiyle ekleri doldurun.
- AttachmentCollection koleksiyonunda yineleme yapın.
- Attachment sınıfının bir örneğini oluşturun ve AttachmentCollection’dan get() yöntemiyle indekslenmiş değeri doldurun.
- Attachment sınıfının save() yöntemiyle eki diske kaydedin.
Java
MailMessage message = MailMessage.load(dataDir + \"message.msg\");
System.out.println(\"Extracting attachments....\");
for (int i = 0; i < message.getAttachments().size(); i++)
{
Attachment att = (Attachment) message.getAttachments().get_Item(i);
System.out.println("Attachment Name: " + att.getName());
String attFileName = att.getName().replace(".eml", "").replace(":", " ").replace("\\", " ").replace("/", " ").replace("?", "");
// Save the attachment to disk
att.save(dataDir + attFileName);
}Apache POI HSMF - Mesaj Eklerini Çıkar
AttachmentChunks sınıfı, MAPIMessage’ın eklerine erişmek için kullanılabilir.
Java
MAPIMessage msg = new MAPIMessage(dataDir + \"message.msg\");
AttachmentChunks[] attachments = msg.getAttachmentFiles();
if (attachments.length > 0)
{
File d = new File(dataDir + "attachments");
if (d.exists() || d.mkdir())
{
for (AttachmentChunks attachment : attachments)
{
String fileName = attachment.attachFileName.toString();
if (attachment.attachLongFileName != null)
{
fileName = attachment.attachLongFileName.toString();
}
File f = new File(d, fileName);
OutputStream fileOut = null;
try
{
fileOut = new FileOutputStream(f);
fileOut.write(attachment.attachData.getValue());
}
finally
{
if (fileOut != null)
{
fileOut.close();
}
}
}
}
}Çalışan Kodu İndir
Örnek Kodu İndir
Daha fazla ayrıntı için ziyaret edin E-posta Mesajındaki Ekleri Yönet.