Aspose.Email.Outlook के साथ संदेश फ़ाइलों का प्रबंधन

Contents
[ ]

PST फ़ोल्डर में MAPI आइटम प्रकार निर्धारित करें

एक PST फ़ाइल आमतौर पर विभिन्न प्रकार के डेटा रखती है, जैसे ईमेल संदेश, कैलेंडर इवेंट्स, संपर्क, और अधिक। यह MapiItemType Aspose.Email की क्लास आपको PST फ़ाइल के भीतर विभिन्न प्रकार के MAPI आइटम्स तक पहुंच और वर्गीकरण करने की अनुमति देती है। नीचे दिया गया कोड दर्शाता है कि PST फ़ोल्डर में MAPI आइटम के प्रकार को कैसे निर्धारित किया जाए:

import aspose.email as ae

pst = ae.storage.pst.PersonalStorage.from_file("test.pst")
folder = pst.root_folder.get_sub_folder("Calendar")
for messageInfo in folder.enumerate_messages():
    msg = pst.extract_message(messageInfo)

    # Get the class type based on msg.SupportedType
    item_type = msg.supported_type

    # Non-supported type. It cannot be accessed as appropriate item type.
    if item_type == ae.mapi.MapiItemType.NONE:
        print("Item type not supported")
    # An email message.
    elif item_type == ae.mapi.MapiItemType.MESSAGE:
        # You can access to MapiMessage properties there.
        # A subject for example
        print(msg.subject)
    # A contact item. Can be accessed as MapiContact.
    elif item_type == ae.mapi.MapiItemType.CONTACT:
        contact = msg.to_mapi_message_item()
        # You can access to MapiContact properties there. 
        # A name_info.display_name for example. 
        print(contact.name_info.display_name)
    # A calendar item. Can be accessed as MapiCalendar.
    elif item_type == ae.mapi.MapiItemType.CALENDAR:
        calendar = msg.to_mapi_message_item()
        # You can access to MapiCalendar properties there. 
        # A location for example. 
        print(calendar.location)
    # A distribution list. Can be accessed as MapiDistributionList.
    elif item_type == ae.mapi.MapiItemType.DIST_LIST:
        dlist = msg.to_mapi_message_item()
        # You can access to MapiDistributionList properties there
    # A Journal entry. Can be accessed as MapiJournal.
    elif item_type == ae.mapi.MapiItemType.JOURNAL:
        journal = msg.to_mapi_message_item()
        # You can access to MapiJournal properties there
    # A StickyNote. Can be accessed as MapiNote.
    elif item_type == ae.mapi.MapiItemType.NOTE:
        note = msg.to_mapi_message_item()
        # You can access to MapiNote properties there
    # A Task item. Can be accessed as MapiTask.
    elif item_type == ae.mapi.MapiItemType.TASK:
        task = msg.to_mapi_message_item()
        # You can access to MapiTask properties there

MSG को MIME संदेश में परिवर्तित करना

Aspose.Email API ToMailMessage मेथड का उपयोग करके MSG फ़ाइल को MIME संदेश में परिवर्तित करने की क्षमता प्रदान करता है।

संदेश के रूपांतरण और लोडिंग के लिए टाइमआउट सेट करना

संदेश रूपांतरण के समय को मिलीसेकंड में सीमित करने के लिए (डिफ़ॉल्ट मान 3 सेकंड), timeout प्रॉपर्टी का MailConversionOptions class उपयोग किया जाता है।

यहाँ बताया गया है कि आप संदेश रूपांतरण और लोडिंग प्रक्रियाओं के लिए टाइमआउट कैसे सेट कर सकते हैं:

import aspose.email as ae

msg = ae.mapi.MapiMessage.load("my.msg")
options = ae.mapi.MailConversionOptions()
options.timeout = 5000
mailMessage = msg.to_mail_message(options)

संदेश रूपांतरण और लोडिंग प्रक्रियाओं के लिए टाइमआउट सेट करके, आप इन संचालन के अधिकतम चलने का समय नियंत्रित कर सकते हैं। टाइमआउट सेट करने के बाद, आप अपने संदेश रूपांतरण और लोडिंग प्रक्रियाओं को आगे बढ़ा सकते हैं।

Outlook टेम्प्लेट (OFT) फ़ाइलों की प्रोसेसिंग

OFT फ़ाइल को लोड, संशोधित और सहेजें

Outlook टेम्प्लेट (OFT) दोहराव वाले ईमेल संदेश भेजने की प्रक्रिया को सरल बनाने का सुविधाजनक तरीका प्रदान करते हैं। हर बार शुरू से एक ही ईमेल लिखने के बजाय, आप Outlook में एक संदेश बना सकते हैं और उसे Outlook टेम्प्लेट (OFT) के रूप में सहेज सकते हैं। बाद में, जब भी आपको समान संदेश भेजने की आवश्यकता हो, आप टेम्प्लेट से जल्दी से उसे जेनरेट कर सकते हैं। यह तरीका आपको संदेश बॉडी, विषय लाइन, फ़ॉर्मेट आदि को फिर से लिखने के प्रयास से बचाता है।

Aspose.Email का MailMessage क्लास Outlook टेम्प्लेट फ़ाइलों (OFT) को लोड और संचालित करने के लिए एक शक्तिशाली टूल प्रदान करता है। जब एक Outlook टेम्प्लेट को MailMessage क्लास की इंस्टेंस में लोड किया जाता है, तो आप आसानी से प्रॉपर्टी जैसे प्रेषक, प्राप्तकर्ता, संदेश बॉडी, विषय आदि को अपडेट कर सकते हैं।

import aspose.email as ae

# Load the OFT file
oft_file_path = "your_template.oft"
mail_message = ae.MailMessage.load(oft_file_path)

# Update properties as needed
mail_message.subject = "Updated Subject"
mail_message.body = "Updated body text."

# Save the updated message as an MSG file
msg_file_path = "updated_message.msg"
mail_message.save(msg_file_path, ae.MailMessageSaveType.outlook_message_format_unicode)

print(f"Updated message saved to {msg_file_path}")

आवश्यक अपडेट करने के बाद, आप ईमेल को उपयोग करके भेज सकते हैं SmtpClient क्लास:

# Send the email
smtpClient.send(message)

Outlook MSG फ़ाइल को टेम्पलेट के रूप में सहेजना

इस प्रयोजन के लिए, आप उपयोग कर सकते हैं MailMessage एक क्लास जो ईमेल बनाता है, फिर उसे OFT फ़ाइल के रूप में सहेजता है। निम्नलिखित कोड नमूना आपको दिखाएगा कि कैसे ईमेल को Outlook टेम्प्लेट के रूप में सहेजा जाए:

import aspose.email as ae

# Create a new MailMessage
message = ae.MailMessage()
message.subject = "Sample Outlook Template"
message.html_body = "<html><body>This is the body of the email.</body></html>"
message.from_address = ae.MailAddress("your.email@example.com", "Your Name")

# Save the MailMessage as an Outlook Template (OFT) file
oft_file_path = "sample_template.oft"
message.save(oft_file_path, ae.SaveOptions.default_oft)

print(f"Outlook Template saved as {oft_file_path}")

OFT या MSG: MapiMessage का प्रकार निर्धारित करें

निम्नलिखित कोड स्निपेट दर्शाता है कि कैसे यह निर्धारित किया जाए कि लोड किया गया MAPI संदेश एक सामान्य ईमेल संदेश है या Outlook टेम्प्लेट (OFT):

msg = ae.mapi.MapiMessage.Load("message.msg");
isOft = msg.is_template # returns false

msg = ae.mapi.MapiMessage.Load("message.oft");
isOft = msg.IsTemplate; # returns true

MSG फ़ाइल लोड करने के बाद, कोड जाँच करता है कि is_template प्रॉपर्टी का MapiMessaage क्लास True या False है। यदि यह false लौटाता है, तो लोड किया गया संदेश एक मानक ईमेल संदेश होता है, न कि Outlook टेम्पलेट; अन्यथा, यदि यह true लौटाता है, तो संदेश एक मानक ईमेल संदेश नहीं है, बल्कि एक Outlook टेम्पलेट है।

MapiMessage या MailMessage को OFT के रूप में सहेजना

यह SaveOptions एक एब्सट्रैक्ट बेस क्लास है जो उपयोगकर्ता को MailMessage को किसी विशिष्ट फ़ॉर्मेट में सहेजते समय अतिरिक्त विकल्प निर्दिष्ट करने की अनुमति देता है। निम्नलिखित कोड नमूना दिखाता है कि कैसे संदेश को OFT फ़ॉर्मेट में सहेजा जाए:

import aspose.email as ae

# Save the MailMessage to OFT format
eml = ae.MailMessage.load("message.eml")

eml.save("message.oft", ae.SaveOptions.default_oft)

# or alternative way 2
save_options = ae.MsgSaveOptions(ae.MailMessageSaveType.outlook_template_format)
eml.save("message.oft", save_options)

# or alternative way 3
save_options = ae.SaveOptions.create_save_options(ae.MailMessageSaveType.outlook_template_format)
eml.save("message.oft", save_options)

# Save the MapiMessage to OFT format
msg = ae.mapi.MapiMessage.load("message.msg")

msg.save("message.oft", ae.SaveOptions.default_oft)

# or alternative way 2
save_options = ae.MsgSaveOptions(ae.MailMessageSaveType.outlook_template_format)
msg.save("message.oft", save_options)

# or alternative way 3
save_options = ae.SaveOptions.create_save_options(ae.MailMessageSaveType.outlook_template_format)
msg.save("message.oft", save_options)

डिजिटल सिग्नेचर के साथ संदेशों का प्रबंधन

लाइब्रेरी प्रदान करती है LoadOptions क्लास, एक एब्सट्रैक्ट बेस क्लास है जो उपयोगकर्ता को किसी विशेष फ़ॉर्मेट से MailMessage लोड करते समय अतिरिक्त विकल्प निर्दिष्ट करने की अनुमति देता है। सिग्नेचर संरक्षित रखने का विकल्प डिफ़ॉल्ट रूप से सेट होता है।

EML से MSG में सिग्नेचर सुरक्षित रखते हुए रूपांतरण

निम्नलिखित कोड उदाहरण दर्शाता है कि संदेश को कैसे लोड करें, इसे MSG फ़ॉर्मेट में बदलें और MSG के रूप में सेव करें (हस्ताक्षर डिफ़ॉल्ट रूप से संरक्षित रहता है):


import aspose.email as ae

# Load mail message
loadOptions = ae.EmlLoadOptions()
message = ae.MailMessage.load("Message.eml", loadOptions)
# Save as MSG
message.save("ConvertEMLToMSG_out.msg", ae.SaveOptions.default_msg_unicode)

MSG से EML में S/MIME संदेश परिवर्तित करें

Aspose.Email आपको MSG से EML में रूपांतरण करने की अनुमति देता है, जिससे डिजिटल हस्ताक्षर को संरक्षित रखा जाता है जैसा कि निम्नलिखित कोड स्निपेट में दिखाया गया है।

import aspose.email as ae

# Load mail message
loadOptions = ae.EmlLoadOptions()
smime_eml = ae.MailMessage.load("smime.eml", loadOptions)

conversion_options = ae.mapi.MapiConversionOptions(ae.mapi.OutlookMessageFormat.UNICODE)
msg = ae.mapi.MapiMessage.from_mail_message(smime_eml, conversion_options)
# Save File to disk
msg.save("ConvertMIMEMessagesFromMSGToEML_out.msg")

Outlook MSG फ़ाइलों के लिए रंग श्रेणी सेट करें

कभी-कभी आपको विशेष महत्त्व वाले ईमेल को अलग पहचानने और दृश्य रूप से व्यवस्थित करने की आवश्यकता हो सकती है। लाइब्रेरी एक विशिष्ट रंग संदेश आइटम को आवंटित करके यह करने का तरीका प्रदान करती है। जब आप किसी आइटम के लिए रंग श्रेणी सेट करते हैं, तो यह आपको एक नज़र में संबंधित आइटम्स को आसानी से पहचानने और खोजने की सुविधा देता है। उपयोग करें FollowUpManager किसी संदेश के लिए रंग श्रेणी सेट करने के लिए क्लास, जैसा कि निम्नलिखित कोड उदाहरण में दिखाया गया है:


import aspose.email as ae

msg = ae.mapi.MapiMessage.load("my.msg")

# Add Two categories
ae.mapi.FollowUpManager.add_category(msg, "Purple Category")
ae.mapi.FollowUpManager.add_category(msg, "Red Category")

# Retrieve the list of available categories
categories = ae.mapi.FollowUpManager.get_categories(msg)

# Remove the specified category and then Clear all categories
ae.mapi.FollowUpManager.remove_category(msg, "Red Category")
ae.mapi.FollowUpManager.clear_categories(msg)

MSG फ़ाइल से फॉलो‑अप जानकारी तक पहुँच

पढ़े जाने और डिलीवरी रसीद जानकारी निकालें

नीचे दिया गया कोड नमूना दिखाता है कि Outlook संदेश (MSG) फ़ाइल से प्राप्तकर्ता जानकारी और उनका ट्रैक स्टेटस कैसे निकालें:

import aspose.email as ae

msg = ae.mapi.MapiMessage.load("received.msg")

for recipient in msg.recipients:
    print(f"Recipient: {recipient.display_name}")
    print(f"Delivery time:  {recipient.properties[ae.mapi.MapiPropertyTag.RECIPIENT_TRACKSTATUS_TIME_DELIVERY]}")
    print(f"Read time:  {recipient.properties[ae.mapi.MapiPropertyTag.RECIPIENT_TRACKSTATUS_TIME_READ]}")

फ़ॉरवर्ड और रिप्लाइ संदेश बनाना

Aspose.Email मौजूदा संदेशों के आधार पर फ़ॉरवर्ड और रिप्लाई संदेश बनाने के सरल तरीके प्रदान करता है।

फ़ॉरवर्ड संदेश बनाना

आप उपयोग कर सकते हैं ForwardMessageBuilder क्लास स्रोत संदेश, प्रेषक, प्राप्तकर्ता, विषय, और बॉडी सेट करके फ़ॉरवर्ड संदेश बनाने के लिए उपयोग की जाती है। फ़ॉरवर्ड संदेश मूल संदेश को अटैचमेंट के रूप में या फ़ॉरवर्ड संदेश की बॉडी में शामिल कर सकते हैं। आप अटैचमेंट्स, हेडर्स, और फ़ॉर्मेटिंग विकल्पों जैसी अतिरिक्त प्रॉपर्टीज़ को कस्टमाइज़ करने की लचीलापन रखते हैं। नीचे दिया गया कोड उदाहरण दिखाता है कि फ़ॉरवर्ड संदेश कैसे बनाएं:


import aspose.email as ae

msg = ae.mapi.MapiMessage.load("original.msg")

builder = ae.tools.ForwardMessageBuilder()
builder.addition_mode = ae.tools.OriginalMessageAdditionMode.TEXTPART

forwardMsg = builder.build_response(msg)
forwardMsg.save("forward_out.msg")

एक उत्तर संदेश बनाना

यह ReplyMessageBuilder क्लास रिप्लाइ सेटिंग्स को कॉन्फ़िगर करने के लिए उपयोग की जाती है, जिसमें स्रोत संदेश, प्रेषक, प्राप्तकर्ता, रिप्लाइ मोड, विषय उपसर्ग, और रिप्लाइ संदेश बॉडी शामिल हैं। रिप्लाइ संदेश विभिन्न मोड जैसे "Reply to Sender" या "Reply to All" में बनाए जा सकते हैं, आपकी आवश्यकताओं के अनुसार। आप अटैचमेंट्स, हेडर्स, और फ़ॉर्मेटिंग विकल्पों जैसे विभिन्न प्रॉपर्टीज़ को कस्टमाइज़ कर सकते हैं। नीचे दिया गया कोड उदाहरण दिखाता है कि फ़ॉरवर्ड संदेश कैसे बनाएं:

import aspose.email as ae

msg = ae.mapi.MapiMessage.load("original.msg")

builder = ae.tools.ReplyMessageBuilder()

# Set ReplyMessageBuilder Properties
builder.reply_all = True
builder.addition_mode = ae.tools.OriginalMessageAdditionMode.TEXTPART
builder.response_text = "<p><b>Dear Friend,</b></p> I want to do is introduce my co-author and co-teacher. <p><a href=\"www.google.com\">This is a first link</a></p><p><a href=\"www.google.com\">This is a second link</a></p>";

replyMsg = builder.build_response(msg)
replyMsg.save("reply_out.msg")