परिचय

Aspose.Email FOSS for Python is now available on PyPI: a free, MIT-licensed library for creating, reading, and converting Outlook .msg फ़ाइलें पूरी तरह से Python में, Microsoft Office या किसी भी मूल एक्सटेंशन पर कोई निर्भरता नहीं। इसे स्थापित करें pip install aspose-email-foss>=26.3 और तुरंत MSG और CFB कंटेनरों के साथ काम करना शुरू करें।.

यह लाइब्रेरी Python 3.10 और उसके बाद के संस्करणों को लक्षित करती है। यह शून्य से Compound File Binary (CFB) फ़ॉर्मेट और MSG संदेश फ़ॉर्मेट को लागू करती है, जिससे आपको ईमेल संदेशों के सीरियलाइज़ और पढ़ने पर निर्धारक नियंत्रण मिलता है। चूँकि कार्यान्वयन शुद्ध Python है, यह Windows, macOS, Linux, और कंटेनराइज़्ड वातावरण में समान रूप से चलता है।.

Aspose.Email FOSS is designed for developers building email processing pipelines, compliance archival tools, forensic analysis workflows, or any application that needs to create or inspect Outlook-compatible message files without a running Exchange or Outlook installation.


मुख्य विशेषताएँ

MSG फ़ाइलें बनाएं

Outlook‑संगत बनाएं .msg फ़ाइलें शून्य से बनाएं, उपयोग करके MapiMessage.create().। मानक MAPI गुण जैसे विषय, प्रेषक, वितरण समय, और डिस्प्ले फ़ील्ड्स को के माध्यम से सेट करें PropertyId enum। प्राप्तकर्ताओं को के साथ जोड़ें add_recipient() और फ़ाइल अटैचमेंट्स को के साथ add_attachment(), फिर परिणाम को डिस्क पर सहेजें।.

from aspose.email_foss import msg

message = msg.MapiMessage.create(
    "Quarterly status update and rollout plan",
    "Hello team,\n\nPlease find the latest rollout summary attached.\n\nRegards,\nEngineering",
)

message.set_property(msg.PropertyId.SENDER_NAME, "Build Agent")
message.set_property(msg.PropertyId.SENDER_EMAIL_ADDRESS, "build.agent@example.com")
message.set_property(msg.PropertyId.INTERNET_MESSAGE_ID, "<example-001@example.com>")

message.add_recipient("alice@example.com", display_name="Alice Example")
message.add_recipient("bob@example.com", display_name="Bob Example")
message.add_recipient(
    "carol@example.com",
    display_name="Carol Example",
    recipient_type=msg.RECIPIENT_TYPE_CC,
)

message.add_attachment("hello.txt", b"sample attachment\n", mime_type="text/plain")
message.save("example-message.msg")

MSG को पढ़ें और EML में परिवर्तित करें

एक मौजूदा लोड करें .msg फ़ाइल के साथ MapiMessage.from_file() और इसे एक मानक Python में परिवर्तित करें EmailMessage ऑब्जेक्ट के माध्यम से to_email_message(). वहाँ से, संग्रहण या SMTP के माध्यम से फ़ॉरवर्ड करने के लिए EML बाइट्स को सीरियलाइज़ करें।.

from aspose.email_foss import msg

with msg.MapiMessage.from_file("example-message.msg") as loaded:
    email_message = loaded.to_email_message()
    eml_bytes = email_message.as_bytes()

with open("example-message.eml", "wb") as f:
    f.write(eml_bytes)

MSG के आंतरिक भागों की जाँच करें

उपयोग करें MsgReader और इसके अंतर्निहित CFBReader एक MSG फ़ाइल की बाइनरी संरचना का निरीक्षण करने के लिए। CFB मेटाडेटा (version, sector size, directory entry count) तक पहुँचें और बाइनरी स्तर पर MAPI प्रॉपर्टी एंट्रीज़ पर इटररेट करें।.

from aspose.email_foss import msg

reader = msg.MsgReader.from_file("example-message.msg")
cfb = reader.cfb_reader

print(f"CFB major_version={cfb.major_version}")
print(f"sector_size={cfb.sector_size}")
print(f"directory_entries={cfb.directory_entry_count}")

for entry in reader.iter_top_level_fixed_length_properties():
    tag = entry.property_tag
    print(f"tag=0x{tag:08X} flags=0x{entry.flags:08X} value={entry.value.hex()}")

reader.close()

निम्न-स्तर CFB पहुँच

किसी भी Compound File Binary कंटेनर को पढ़ें और ट्रैवर्स करें। CFBReader. स्टोरेज और स्ट्रीम को सूचीबद्ध करें, नाम द्वारा पाथ को हल करें, और कस्टम प्रोसेसिंग के लिए कच्चा स्ट्रीम डेटा निकालें।.

from aspose.email_foss.cfb import CFBReader

reader = CFBReader.from_file("example-message.msg")

for entry in reader.iter_storages():
    print(f"Storage: {entry.name}")

for entry in reader.iter_streams():
    data = reader.get_stream_data(entry.stream_id)
    print(f"Stream: {entry.name} size={len(data)}")

reader.close()

त्वरित प्रारंभ

लाइब्रेरी इंस्टॉल करें और दस लाइनों से कम में अपनी पहली MSG फ़ाइल बनाएं:

pip install aspose-email-foss>=26.3
from aspose.email_foss import msg

message = msg.MapiMessage.create("Hello from Python", "This is a test message.")
message.set_property(msg.PropertyId.SENDER_EMAIL_ADDRESS, "sender@example.com")
message.add_recipient("recipient@example.com", display_name="Recipient")
message.save("hello.msg")

with msg.MapiMessage.from_file("hello.msg") as loaded:
    eml = loaded.to_email_message()
    print(eml["Subject"])

समर्थित फ़ॉर्मेट्स

फ़ॉर्मेटआयातनिर्यात
MSGहाँहाँ
CFBहाँहाँ

ओपन सोर्स और लाइसेंसिंग

Aspose.Email FOSS for Python is released under the MIT License. आप इसे व्यक्तिगत, आंतरिक और व्यावसायिक प्रोजेक्ट्स में बिना किसी प्रतिबंध के उपयोग कर सकते हैं। स्रोत कोड उपलब्ध है पर GitHub.


शुरू करना