MSG फ़ाइलों का लोडिंग और पार्सिंग
यह अनुभाग बताता है कि Microsoft Outlook संदेश फ़ाइलें (.msg) को कैसे लोड और पार्स किया जाए। Aspose.Email API एक MapiMessage विभिन्न परिदृश्यों के लिए कई स्थैतिक लोडिंग फ़ंक्शंस के साथ MSG फ़ाइलें लोड करने के लिए क्लास। नीचे दिए गए कोड स्निपेट दर्शाते हैं कि फ़ाइल या स्ट्रीम से MSG फ़ाइलें कैसे लोड की जाएं।
Try it out!
नि:शुल्क के साथ ऑनलाइन ईमेल फ़ाइलें पार्स करें Aspose.Email पार्सर ऐप.
डिस्क से MSG फ़ाइल लोड करें
निम्नलिखित कोड स्निपेट दर्शाता है कि डिस्क से MSG फ़ाइलें कैसे लोड की जाएँ:
from aspose.email.mapi import MapiMessage
# Create an instance of MapiMessage from file
msg = MapiMessage.load("message.msg")
# Get subject
print("Subject: " + msg.subject)
# Get from address
print("From: " + msg.sender_email_address)
# Get body
print("Body: " + msg.body)
# Get recipients information
recipients = ", ".join([r.email_address for r in msg.recipients])
print("Recipients: " + recipients)
# Get attachments
for att in msg.attachments:
print(att.file_name)
print(att.display_name)
स्ट्रीम से MSG फ़ाइल लोड करें
निम्नलिखित कोड स्निपेट दर्शाता है कि स्ट्रीम से MSG फ़ाइलें कैसे लोड की जाएँ:
from aspose.email.mapi import MapiMessage
import io
# Read the file into a byte array
file_path = "message.msg"
with open(file_path, "rb") as file:
bytes_data = file.read()
# Create a memory stream from the byte array
stream = io.BytesIO(bytes_data)
stream.seek(0)
# Create an instance of MapiMessage from the stream
msg = MapiMessage.load(stream)
# Get subject
print("Subject: " + msg.subject)
# Get from address
print("From: " + msg.sender_email_address)
# Get body
print("Body: " + msg.body)
एंबेडेड EML फ़ॉर्मेट को संरक्षित रखते हुए EML को MSG में बदलना
EML फ़ाइलें लोड की जा सकती हैं MapiMessage क्लास को एक … इंस्टैंसिएट करके MailMessage ऑब्जेक्ट और इसे पास करके MapiMessage.from_mail_message विधि। यदि EML फ़ाइल में एम्बेडेड फ़ाइलें हैं, तो उपयोग करें MapiConversionOptions.preserve_embedded_message_format एम्बेडेड फ़ाइलों के फ़ॉर्मेट को बनाए रखने के लिए। नीचे दिया गया कोड स्निपेट दर्शाता है कि एम्बेडेड EML फ़ाइलों के फ़ॉर्मेट को संरक्षित रखते हुए EML फ़ाइलों को MapiMessage में कैसे लोड करें।
निम्नलिखित कोड स्निपेट दर्शाता है कि एम्बेडेड संदेश फ़ॉर्मेट को संरक्षित रखते हुए EML फ़ाइल को MSG फ़ाइल में कैसे बदलें:
from aspose.email import MailMessage, EmlLoadOptions
from aspose.email.mapi import MapiMessage, MapiConversionOptions, OutlookMessageFormat
eml_file = "message.eml"
# Load the EML file
eml_options = EmlLoadOptions()
eml = MailMessage.load(eml_file, eml_options)
# Create MapiConversionOptions
conversion_options = MapiConversionOptions()
conversion_options.format = OutlookMessageFormat.UNICODE
# Preserve Embedded Message Format
conversion_options.preserve_embedded_message_format = True
# Convert EML to MSG with options
msg = MapiMessage.from_mail_message(eml, conversion_options)