Outlook MSG Dosyalarında Ekleri Yönet

Aspose.Email for C++, Microsoft Outlook MSG dosyaları ile çalışırken ekleri erişme, kaydetme, kaldırma ve gömme için zengin bir API sağlar. Ekler şunun aracılığıyla işlenir: MapiMessage sınıfı, onun Attachments özellik, bir MapiAttachmentCollection.

Bir MSG Dosyasından Ekleri Kaydet

Bir MSG dosyasından ekleri çıkarmak ve kaydetmek için:

  1. Mesajı şu şekilde yükleyin: MapiMessage::Load.
  2. İçinde döngü yap MapiAttachmentCollection.
  3. Her eki şu şekilde kaydedin: MapiAttachment::Save() metod.
// Create an instance of MapiMessage from file
System::SharedPtr<MapiMessage> message = MapiMessage::Load(fileName);
    
// Iterate through the attachments collection
    
{
    auto attachment_enumerator = (message->get_Attachments())->GetEnumerator();
    decltype(attachment_enumerator->get_Current()) attachment;
    while (attachment_enumerator->MoveNext() && (attachment = attachment_enumerator->get_Current(), true))
    {
        // Save the individual attachment
        attachment->Save(dataDir + attachment->get_FileName());
    }
}

Ekleri Kaldır

Aspose.Email for C++ MSG dosyalarından ekleri kaldırmak için iki yol sunar:

Mesaj dosyasının yolunu parametre olarak alır. Genel bir statik metod olarak uygulanmıştır, bu yüzden nesne oluşturmanıza gerek yoktur. Bu statik yardımcı metod, bir mesaj dosyasındaki tüm ekleri kaldırır.

Aşağıdaki kod parçacığı bu yöntemin nasıl kullanılacağını gösterir.

MSG dosyasını tam olarak ayrıştırmadan ekleri kaldırdığı için daha hızlı çalışır.

MSG Ekleri Ekle

MSG dosyaları, standart veya gömülü ekler olarak diğer MSG dosyalarını içerebilir. Aşırı yüklenmiş Add yöntemler MapiAttachmentCollection Outlook mesajlarını gömmek için.

Aşağıdaki kod örneği, belirli gönderici, alıcı, konu ve gövde ile yeni bir MAPI mesajı oluşturmayı, ardından mevcut bir MSG dosyasını gömülü mesaj olarak eklemeyi ve son olarak gömülü ekli oluşan mesajı yeni bir MSG dosyasına kaydetmeyi göstermektedir.

System::SharedPtr<MapiMessage> message = System::MakeObject<MapiMessage>(L"from@test.com", L"to@test.com", L"Subj", L"This is a message body");
System::SharedPtr<MapiMessage> attachMsg = MapiMessage::Load(L"Message.msg");
message->get_Attachments()->Add(L"Weekly report.msg", attachMsg);
message->Save(dataDir + L"WithEmbeddedMsg_out.msg");