Outlook MSG फ़ाइलों में अटैचमेंट्स प्रबंधित करें
Aspose.Email for C++ Microsoft Outlook MSG फ़ाइलों के साथ कार्य करते समय अटैचमेंट्स तक पहुँचने, सहेजने, हटाने और एम्बेड करने के लिए एक समृद्ध API प्रदान करता है। अटैचमेंट्स को इस माध्यम से संभाला जाता है MapiMessage क्लास, उसका उपयोग करके Attachments प्रॉपर्टी, जो एक MapiAttachmentCollection.
MSG फ़ाइल से अटैचमेंट्स सहेजें
MSG फ़ाइल से अटैचमेंट्स निकालने और सहेजने के लिए:
- संदेश को लोड करें, उपयोग करके MapiMessage::Load.
- परिचालित करें MapiAttachmentCollection.
- प्रत्येक अटैचमेंट को उपयोग करके सहेजें MapiAttachment::Save() विधि।
// 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());
}
}
अटैचमेंट्स हटाएँ
Aspose.Email for C++ MSG फ़ाइलों से अटैचमेंट्स हटाने के दो तरीके प्रदान करता है:
- Call the RemoveAttachments() विधि
यह संदेश फ़ाइल का पाथ पैरामीटर के रूप में लेता है। इसे एक सार्वजनिक स्थैतिक मेथड के रूप में लागू किया गया है, इसलिए आपको ऑब्जेक्ट को इंस्टैंसिएट करने की आवश्यकता नहीं है। यह स्थैतिक हेल्पर मेथड संदेश फ़ाइल से सभी अटैचमेंट्स को हटा देता है।
निम्नलिखित कोड स्निपेट दिखाता है कि इस मेथड का उपयोग कैसे करें।
- Call the DestoryAttachment() विधि
यह तेज़ काम करता है क्योंकि यह MSG फ़ाइल को पूर्ण रूप से पार्स किए बिना अटैचमेंट्स को हटाता है।
MSG अटैचमेंट्स जोड़ें
MSG फ़ाइलें अन्य MSG फ़ाइलों को या तो मानक या एम्बेडेड अटैचमेंट के रूप में रख सकती हैं। ओवरलोडेड का उपयोग करें Add में विधियों MapiAttachmentCollection Outlook संदेशों को एम्बेड करने के लिए।
निम्नलिखित कोड नमूना दर्शाता है कि कैसे निर्दिष्ट प्रेषक, प्राप्तकर्ता, विषय, और बॉडी के साथ एक नया MAPI संदेश बनाएं, फिर एक मौजूदा MSG फ़ाइल को एम्बेडेड संदेश के रूप में अटैच करें, और अंत में एम्बेडेड अटैचमेंट के साथ resulting संदेश को नई MSG फ़ाइल में सहेजें।
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");