Aspose.Email ve Apache POI HSMF kullanarak Mesaj Eklerini Ayıkla

Aspose.Email - Mesaj Eklerini Çıkar

Mevcut mesajlardan ekleri kaydetmek için:

  1. MailMessage sınıfının bir örneğini oluşturun.
  2. Doğru MessageFormat’ı belirterek MailMessage sınıfının load() yöntemiyle mevcut e-posta mesajını yükleyin.
  3. AttachmentCollection sınıfının bir örneğini oluşturun ve MaiMessage örneğinden getAttachments() yöntemiyle ekleri doldurun.
  4. AttachmentCollection koleksiyonunda yineleme yapın.
  5. Attachment sınıfının bir örneğini oluşturun ve AttachmentCollection’dan get() yöntemiyle indekslenmiş değeri doldurun.
  6. 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