ईमेल लोड करना, सहेजना और रूपांतरित करना

Contents
[ ]

ईमेल फ़ाइल फ़ॉर्मेट का पता लगाना

Aspose.Email API प्रदान करती है क्षमता कि प्रदत्त संदेश फ़ाइल का फ़ाइल फ़ॉर्मेट पता लगाया जा सके। DetectFileFormat की विधि FileFormatUtil इसको प्राप्त करने के लिए क्लास का उपयोग किया जा सकता है। निम्नलिखित क्लास और मेथड का उपयोग लोड किए गए फ़ाइल फ़ॉर्मेट का पता लगाने के लिए किया जा सकता है:

निम्नलिखित कोड स्निपेट दिखाता है कि फ़ाइल फ़ॉर्मेट का पता कैसे लगाया जाए:

from aspose.email.tools import FileFormatUtil

# Detect file format and get the detected load format
info = FileFormatUtil.detect_file_format(data_dir + "message.msg")
print("The message format is: " + str(info.file_format_type))

लोड विकल्पों के साथ संदेश लोड करना

निम्नलिखित कोड स्निपेट दिखाता है कि लोड विकल्पों के साथ संदेश को कैसे लोड किया जाए।

from aspose.email import MailMessage, EmlLoadOptions, HtmlLoadOptions, MhtmlLoadOptions, MsgLoadOptions

# Load Eml, html, mhtml, msg, and dat files
mail_message = MailMessage.load(data_dir + "message.eml", EmlLoadOptions())
MailMessage.load(data_dir + "description.html", HtmlLoadOptions())
MailMessage.load(data_dir + "message.mhtml", MhtmlLoadOptions())
MailMessage.load(data_dir + "message.msg", MsgLoadOptions())

# Loading with custom options
eml_load_options = EmlLoadOptions()
eml_load_options.preferred_text_encoding = "utf-8"
eml_load_options.preserve_tnef_attachments = True

MailMessage.load(data_dir + "description.html", eml_load_options)

html_load_options = HtmlLoadOptions()
html_load_options.preferred_text_encoding = "utf-8"
html_load_options.should_add_plain_text_view = True
html_load_options.path_to_resources = data_dir

MailMessage.load(data_dir + "description.html", html_load_options)

लोडिंग के दौरान एम्बेडेड संदेश फ़ॉर्मेट को संरक्षित रखना

from aspose.email import MailMessage, EmlLoadOptions, HtmlLoadOptions, MhtmlLoadOptions, MsgLoadOptions
from aspose.email.tools import FileFormatUtil

eml_load_options = EmlLoadOptions()
eml_load_options.preserve_embedded_message_format = True

mail = MailMessage.load(data_dir + "message.eml", eml_load_options)

file_format = FileFormatUtil.detect_file_format(mail.attachments[0].content_stream).file_format_type

print("Embedded message file format: " + str(file_format))

EMLX फ़ाइल लोड करना

Apple Mail अपने संदेशों को EMLX प्रारूप में संग्रहीत करता है। उपयोग करें EmlxLoadOptions वर्ग नियंत्रित करता है कि ऐसी फ़ाइल कैसे लोड की जाए। यह वही विकल्प प्रदान करता है जैसा कि EmlLoadOptions करता है — एन्कोडिंग प्राथमिकता, एम्बेडेड संदेश फ़ॉर्मेट संरक्षण और हस्ताक्षर हटाना:

import aspose.email as ae

# Instantiate EmlxLoadOptions
load_options = ae.EmlxLoadOptions()
load_options.preferred_text_encoding = "utf-8"
load_options.preserve_embedded_message_format = True
load_options.remove_signature = True

# Load the EMLX file
emlx = ae.MailMessage.load(data_dir + "message.emlx", load_options)
print(emlx.subject)

हस्ताक्षर के साथ या बिना संदेश लोड करना

हस्ताक्षर संरक्षण डिफ़ॉल्ट व्यवहार है जब संदेश लोड किया जाता है। लोड करने के दौरान हस्ताक्षर हटाने के लिए, सेट करें remove_signature लोड विकल्पों की property को True:

import aspose.email as ae

options = ae.EmlLoadOptions()
options.remove_signature = True

msg = ae.MailMessage.load(data_dir + "signed.eml", options)
print("Is signed: " + str(msg.is_signed))

ईमेल को सहेजना और रूपांतरित करना

Aspose.Email किसी भी संदेश प्रकार को अन्य फ़ॉर्मेट में आसानी से बदल सकता है। इस सुविधा को प्रदर्शित करने के लिए, इस लेख का कोड डिस्क से तीन प्रकार के संदेश लोड करता है और उन्हें अन्य फ़ॉर्मेट में वापस सहेजता है। बेस क्लास SaveOptions और इन क्लासों को EmlSaveOptions, MsgSaveOptions, MhtSaveOptions, HtmlSaveOptions अन्य फ़ॉर्मेट में संदेश सहेजते समय अतिरिक्त सेटिंग्स के लिए उपयोग किया जा सकता है। लेख दर्शाता है कि इन क्लासों का उपयोग करके एक सैंपल ईमेल को कैसे सहेजा जाए:

  • EML फ़ॉर्मेट।
  • Outlook MSG।
  • MHTML फ़ॉर्मेट।
  • HTML फ़ॉर्मेट।

EML के रूप में सहेजना

निम्नलिखित कोड स्निपेट दिखाता है कि EML संदेश को लोड करके डिस्क पर उसी फ़ॉर्मेट में कैसे सहेजा जाए।

from aspose.email import MailMessage, SaveOptions

# Initialize and Load an existing EML file by specifying the MessageFormat
mail_message = MailMessage.load(data_dir + "message.eml")

mail_message.save(data_dir + "LoadAndSaveFileAsEML_out.eml", SaveOptions.default_eml)

EML फ़ाइलों में बाउंड्री को संरक्षित रखना

निम्नलिखित कोड स्निपेट दिखाता है कि EML फ़ाइल को लोड करके मूल बाउंड्री को संरक्षित रखते हुए उसी फ़ॉर्मेट में कैसे सहेजा जाए।

from aspose.email import MailMessage, EmlSaveOptions, MailMessageSaveType

mail_message = MailMessage.load(data_dir + "message.eml")

# Save as eml with preserved original boundaries
eml_save_options = EmlSaveOptions(MailMessageSaveType.eml_format)

mail_message.save(data_dir + "PreserveOriginalBoundaries_out.eml", eml_save_options)

MIME बाउंड्री स्ट्रिंग्स को कस्टमाइज़ करें

Aspose.Email आपको MIME संदेशों में उपयोग किए जाने वाले बाउंडरी टेम्पलेट को कॉन्फ़िगर करने की अनुमति देता है। यह प्राप्त होता है boundaries_template की प्रॉपर्टी EmlSaveOptions क्लास।

कस्टम टेम्प्लेट सेट करके आप निर्धारित कर सकते हैं कि MIME बाउंड्री कैसे जनरेट हों। टेम्प्लेट में {#} वैल्डकार्ड को इनक्रिमेंटल बाउंड्री नंबर से प्रतिस्थापित किया जाएगा, जिससे डायनेमिक और पठनीय बाउंड्री स्ट्रिंग्स बनेंगी।

यदि boundaries_template सेट नहीं है (डिफ़ॉल्ट None है), लाइब्रेरी अपना आंतरिक बाउंड्री फ़ॉर्मेट उपयोग करती है।

निम्नलिखित कोड उदाहरण दिखाता है कि .eml फ़ॉर्मेट में ईमेल संदेश को सहेजते समय MIME बाउंड्री स्ट्रिंग्स को कैसे कस्टमाइज़ किया जाए:

import aspose.email as ae

# Create a sample MailMessage
message = ae.MailMessage()
message.subject = "Custom MIME Boundary"
message.body = "This message uses a custom MIME boundary template."
message.to.append(ae.MailAddress("recipient@example.com"))

# Configure save options with a custom boundary template
save_options = ae.EmlSaveOptions(ae.MailMessageSaveType.eml_format)
save_options.boundaries_template = "boundary--{#}"

# Save the message to .eml with custom boundaries
message.save("Custom_Boundary_Message.eml", save_options)

यहाँ ऊपर दिखाए गए कोड का उपयोग करके कस्टम बाउंड्री के साथ सहेजे गए संदेश संरचना का उदाहरण है:

From: sender@example.com  
To: recipient@example.com  
Subject: Custom_Boundary_Message  
Date: Fri, 27 Dec 2024 12:00:00 +0000
Content-Type: multipart/mixed;
 boundary="boundary--1"

This is a multi-part message in MIME format.

--boundary--1
Content-Type: multipart/alternative; boundary="boundary--2"


--boundary--2
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

Content-Type: text/plain; charset="us-ascii"

This is the plain text content of the email.


--boundary--2
Content-Type: text/html; charset="windows-1251"
Content-Transfer-Encoding: quoted-printable

<html>
  <body>
    <p>This is the <b>HTML</b> content of the email.</p>
  </body>
</html>

--boundary--2--

--boundary--1
Content-Type: application/octet-stream; name="report-2023-08.xlsx"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="report-2023-08.xlsx"

UEsDBBQABgAIAAAAIQBi7...

--boundary--1--

EML फ़ाइलों में TNEF अटैचमेंट को संरक्षित रखना

निम्नलिखित कोड स्निपेट दिखाता है कि TNEF अटैचमेंट को संरक्षित रखते हुए EML फ़ाइल को कैसे सहेजा जाए।

from aspose.email import MailMessage, EmlSaveOptions, MailMessageSaveType, FileCompatibilityMode

mail_message = MailMessage.load(data_dir + "message.eml")

# Save as eml with preserved attachment
eml_save_options = EmlSaveOptions(MailMessageSaveType.eml_format)
eml_save_options.file_compatibility_mode = FileCompatibilityMode.PRESERVE_TNEF_ATTACHMENTS

mail_message.save(data_dir + "PreserveTNEFAttachment_out.eml", eml_save_options)

MSG के रूप में सहेजना

निम्नलिखित कोड स्निपेट दिखाता है कि EML संदेश को लोड करके उपयुक्त विकल्प का उपयोग करके MSG में कैसे परिवर्तित किया जाए SaveOptions.

from aspose.email import MailMessage, SaveOptions, MailMessageSaveType, FileCompatibilityMode

# Initialize and Load an existing EML file by specifying the MessageFormat
eml = MailMessage.load(data_dir + "message.eml")

# Save the Email message to disk in ASCII format and Unicode format
eml.save(data_dir + "AnEmail_out.msg", SaveOptions.default_msg_unicode)

MSG फ़ाइलों में तिथियों को संरक्षित रखना

यह MsgSaveOptions class आपको स्रोत संदेश को Outlook Message फ़ाइल (MSG) के रूप में तिथियों को संरक्षित रखते हुए सहेजने की अनुमति देती है। निम्नलिखित कोड स्निपेट दिखाता है कि EML फ़ाइल को MSG के रूप में कैसे सहेजा जाए और तिथियों को संरक्षित रखा जाए।

from aspose.email import MailMessage, MsgSaveOptions, MailMessageSaveType, FileCompatibilityMode

# Initialize and Load an existing EML file by specifying the MessageFormat
eml = MailMessage.load(data_dir + "message.eml")

# Save as msg with preserved dates
msg_save_options = MsgSaveOptions(MailMessageSaveType.outlook_message_format_unicode)
msg_save_options.preserve_original_dates = True

eml.save(data_dir + "outTest_out.msg", msg_save_options)

MHTML के रूप में सहेजना

विभिन्न MHTML विकल्पों का उपयोग करके इच्छित परिणाम प्राप्त किए जा सकते हैं। निम्न कोड स्निपेट दिखाता है कि EML संदेश को कैसे लोड किया जाए MailMessage और इसे MHTML में परिवर्तित करें।

from aspose.email import MailMessage, SaveOptions, MailMessageSaveType, FileCompatibilityMode

# Initialize and Load an existing EML file by specifying the MessageFormat
eml = MailMessage.load(data_dir + "message.eml")

eml.save(data_dir + "AnEmail_out.mhtml", SaveOptions.default_mhtml)

कस्टम MHTML रूपांतरण सेटिंग्स

यह MhtSaveOptions क्लास MHTML फ़ॉर्मेट में ईमेल संदेश सहेजने के लिए अतिरिक्त विकल्प प्रदान करती है। एनेमरेटर MhtFormatOptions यह अतिरिक्त ईमेल जानकारी को आउटपुट MHTML में लिखना संभव बनाता है। निम्न अतिरिक्त फ़ील्ड्स लिखे जा सकते हैं:

  • NONE - कोई विशिष्ट सेटिंग्स निर्दिष्ट नहीं हैं।
  • WRITE_HEADER - संकेत देता है कि हेडर जानकारी लिखी जानी चाहिए।
  • WRITE_OUTLINE_ATTACHMENTS - संकेत देता है कि outline अटैचमेंट लिखे जाएँ।
  • WRITE_COMPLETE_EMAIL_ADDRESS - संकेत देता है कि पूर्ण ईमेल पता सभी ईमेल हेडर में लिखा जाना चाहिए।
  • NO_ENCODE_CHARACTERS - संकेत देता है कि कैरेक्टर की कोई ट्रांसफर एन्कोडिंग उपयोग नहीं की जानी चाहिए।
  • HIDE_EXTRA_PRINT_HEADER - संकेत देता है कि PageHeader अदृश्य रहेगा।
  • WRITE_COMPLETE_TO_EMAIL_ADDRESS - संकेत देता है कि पूर्ण ईमेल पता ‘To’ हेडर में लिखा जाना चाहिए।
  • WRITE_COMPLETE_FROM_EMAIL_ADDRESS - संकेत देता है कि पूर्ण ईमेल पता ‘From’ हेडर में लिखा जाना चाहिए।
  • WRITE_COMPLETE_CC_EMAIL_ADDRESS - संकेत देता है कि पूर्ण ईमेल पता ‘Cc’ हेडर में लिखा जाना चाहिए।
  • WRITE_COMPLETE_BCC_EMAIL_ADDRESS - संकेत देता है कि पूर्ण ईमेल पता ‘Bcc’ हेडर में लिखा जाना चाहिए।
  • RENDER_CALENDAR_EVENT - संकेत देता है कि कैलेंडर इवेंट से टेक्स्ट आउटपुट mhtml में लिखा जाना चाहिए।
  • SKIP_BYTE_ORDER_MARK_IN_BODY - संकेत देता है कि Byte Order Mark (BOM) बाइट्स बॉडी में लिखे जाने चाहिए।
  • RENDER_V_CARD_INFO - संकेत देता है कि VCard AlternativeView से टेक्स्ट आउटपुट mhtml में लिखा जाना चाहिए।
  • DISPLAY_AS_OUTLOOK - संकेत देता है कि From हेडर Outlook की तरह प्रदर्शित होगा।
  • RENDER_TASK_FIELDS - संकेत देता है कि विशिष्ट टास्क फ़ील्ड आउटपुट mhtml में लिखे जाने चाहिए।

निम्नलिखित कोड स्निपेट दिखाता है कि वैकल्पिक सेटिंग्स के साथ EML फ़ाइल को MHTML में कैसे परिवर्तित किया जाए।

from aspose.email import MailMessage, MhtSaveOptions, MhtFormatOptions, MailMessageSaveType, FileCompatibilityMode

# Load an existing EML file
eml = MailMessage.load(data_dir + "message.eml")

# Save as mht with header
mht_save_options = MhtSaveOptions()

# Specify formatting options required
# Here we are specifying to write header information to output without writing extra print header
# and the output headers should be displayed as the original headers in the message
mht_save_options.mht_format_options = MhtFormatOptions.WRITE_HEADER | MhtFormatOptions.HIDE_EXTRA_PRINT_HEADER | MhtFormatOptions.DISPLAY_AS_OUTLOOK

# Check the body encoding for validity.
mht_save_options.check_body_content_encoding = True

eml.save(data_dir + "outMessage_out.mht", mht_save_options)

MHTML रूपांतरण में कैलेंडर इवेंट शामिल करना

यह MhtFormatOptions.RenderCalendarEvent कैलेंडर इवेंट को आउटपुट MHTML में रेंडर करता है। निम्नलिखित कोड स्निपेट दिखाता है कि MHTML में बदलते समय कैलेंडर इवेंट को कैसे रेंडर किया जाए:

from aspose.email import MailMessage, MhtSaveOptions, MhtFormatOptions, MhtTemplateName, MailMessageSaveType, FileCompatibilityMode

file_name = "message.msg"

# Load the MSG file
msg = MailMessage.load(data_dir + file_name)

# Create MHT save options
options = MhtSaveOptions()
options.mht_format_options = MhtFormatOptions.WRITE_HEADER | MhtFormatOptions.RENDER_CALENDAR_EVENT

# Save the message as MHTML
msg.save(data_dir + "Meeting with Recurring Occurrences.mhtml", options)

इनलाइन इमेजेज़ के बिना ईमेल को MHT में एक्सपोर्ट करना

from aspose.email import MailMessage, MhtSaveOptions, MhtFormatOptions, MhtTemplateName, MailMessageSaveType, FileCompatibilityMode

# Load the EML file
eml = MailMessage.load(data_dir + "message.eml")

# Create MHT save options
mht_save_options = MhtSaveOptions()
mht_save_options.skip_inline_images = True

# Save the message as MHTML without inline images
eml.save(data_dir + "EmlToMhtmlWithoutInlineImages_out.mht", mht_save_options)

कस्टम टाइम ज़ोन के साथ ईमेल को MHT में एक्सपोर्ट करना

MailMessage class प्रदान करता है TimeZoneOffset MHT में एक्सपोर्ट करते समय कस्टम टाइम ज़ोन सेट करने के लिए प्रॉपर्टी। निम्नलिखित कोड स्निपेट दिखाता है कि कस्टम टाइम ज़ोन के साथ ईमेल को MHT में कैसे एक्सपोर्ट किया जाए:

from aspose.email import MailMessage, MhtSaveOptions, MhtFormatOptions, MhtTemplateName, MailMessageSaveType, FileCompatibilityMode
from datetime import timedelta

# Load the EML file
eml = MailMessage.load(data_dir + "message.eml")

# Set the local time for message date
eml.time_zone_offset = timedelta(hours=-8)

# The dates will be rendered by the local system time zone
mht_save_options = MhtSaveOptions()
mht_save_options.mht_format_options = MhtFormatOptions.WRITE_HEADER
eml.save(data_dir + "ExportEmailToMHTWithCustomTimezone_out.mhtml", mht_save_options)

MHTML आउटपुट में फ़ॉन्ट समायोजित करना

यह css_styles की प्रॉपर्टी MhtSaveOptions वर्ग स्टाइल शीट रखता है जो आउटपुट फ़ाइल में लिखी जाती है। बंद होने से पहले अपने नियम डालें </style> डिफ़ॉल्ट उपस्थिति को ओवरराइड करने के लिए टैग:

import aspose.email as ae

eml = ae.MailMessage.load(data_dir + "message.eml")

options = ae.MhtSaveOptions()
css_insert_pos = options.css_styles.rfind("</style>")
options.css_styles = (options.css_styles[:css_insert_pos]
                      + ".PlainText{ font-family: sans-serif; }"
                      + options.css_styles[css_insert_pos:])

eml.save(data_dir + "message_out.mhtml", options)

HTML के रूप में सहेजना

यह HtmlSaveOptions क्लास आपको संदेश बॉडी को HTML में एक्सपोर्ट करने देता है, जिसमें resource_rendering_mode प्रॉपर्टी के माध्यम से एम्बेडेड रिसोर्सेज़ की रेंडरिंग को नियंत्रित किया जा सकता है। नीचे दिया गया कोड स्निपेट दिखाता है कि संदेश को HTML के रूप में कैसे सहेजें; डिफ़ॉल्ट रूप से रिसोर्सेज़ HTML में एम्बेड होते हैं (ResourceRenderingMode.EMBED_INTO_HTML), जबकि ResourceRenderingMode.SAVE_TO_FILE उन्हें अलग फ़ाइलों में लिखता है।

from aspose.email import MailMessage, SaveOptions, HtmlSaveOptions, HtmlFormatOptions, ResourceRenderingMode

# Load the EML file
message = MailMessage.load(data_dir + "message.eml")

# Save the Email message as HTML
message.save(data_dir + "SaveAsHTML_out.html", SaveOptions.default_html)

# OR

eml = MailMessage.load(data_dir + "message.eml")
options = HtmlSaveOptions()
options.resource_rendering_mode = ResourceRenderingMode.SAVE_TO_FILE
options.html_format_options = (
    HtmlFormatOptions.WRITE_HEADER
    | HtmlFormatOptions.WRITE_COMPLETE_EMAIL_ADDRESS
)  # save the message headers to output HTML using the formatting options
eml.save(data_dir + "SaveAsHTML1_out.html", options)

संसाधनों के रेंडरिंग को नियंत्रित करना

यह resource_rendering_mode की प्रॉपर्टी HtmlSaveOptions वर्ग परिभाषित करता है कि संदेश संसाधन (इनलाइन चित्र, उदाहरण के लिये) आउटपुट HTML में कैसे लिखे जाएँ। यह स्वीकार करता है मान ResourceRenderingMode इनोमरेशन:

  • EMBED_INTO_HTML – रिसोर्सेज को HTML में base64 स्ट्रिंग्स के रूप में एम्बेड करें। यह डिफ़ॉल्ट मान है।
  • SAVE_TO_FILE – रिसोर्सेज को फ़ाइलों में सहेजें और प्रत्येक फ़ाइल के पाथ को HTML में डालें। src टैग।
  • SUBSTITUTE_FROM_FILE – एक कस्टम फ़ाइल को आइकन के रूप में उपयोग करें और उसका पाथ HTML में डालें। src टैग।
  • NONE – HTML में रिसोर्सेज को रेंडर न करें।

जब संसाधन फ़ाइलों में सहेजे जाते हैं, तो use_relative_path_to_resources गुणधर्म नियंत्रित करता है कि HTML में लिखे गए पाथ सापेक्ष हों या पूर्ण.

import aspose.email as ae

msg = ae.MailMessage.load(data_dir + "EmailWithAttandEmbedded.eml")

options = ae.HtmlSaveOptions()
options.resource_rendering_mode = ae.ResourceRenderingMode.SAVE_TO_FILE
options.use_relative_path_to_resources = True

msg.save(data_dir + "EmailWithAttandEmbedded.html", options)

Outlook टेम्प्लेट (.OFT) के रूप में सहेजना

एक Outlook टेम्पलेट के रूप में संदेश सहेजने के लिए, उपयोग करें SaveOptions.default_oft विकल्प — वे रखते हैं outlook_template_format सेव प्रकार। वही परिणाम एक बनाकर प्राप्त किया जाता है MsgSaveOptions ऑब्जेक्ट के साथ MailMessageSaveType.outlook_template_format.

निम्न कोड स्निपेट दिखाता है कि कैसे संदेश को Outlook टेम्प्लेट (.oft) फ़ाइल के रूप में सहेजा जाए:

from aspose.email import MailMessage, SaveOptions

eml = MailMessage("test@from.to", "test@to.to", "template subject", "Template body")

oft_eml_file_name = "EmlAsOft_out.oft"
options = SaveOptions.default_oft

eml.save(data_dir + oft_eml_file_name, options)

EML को MSG में रूपांतरित करना (MailMessage से MapiMessage)

एक को परिवर्तित करने के लिए MailMessage ऑब्जेक्ट जिसे EML फ़ाइल से लोड किया गया है, को एक MapiMessage ऑब्जेक्ट, उपयोग करें MapiConversionOptions क्लास। यह रूपांतरण अक्सर आवश्यक होता है क्योंकि दो ऑब्जेक्ट अलग-अलग उद्देश्यों की सेवा करते हैं। MapiMessage विशेष रूप से Microsoft Outlook और Exchange Server के साथ संगतता के लिए डिज़ाइन किया गया है, क्योंकि यह मैसेजिंग एप्लिकेशन प्रोग्रामिंग इंटरफ़ेस (MAPI) फ़ॉर्मेट का पालन करता है। इससे सुनिश्चित होता है कि MSG फ़ाइलों में रूपांतरित ईमेल Microsoft उत्पादों के साथ पूर्णतः संगत हों और सीधे Outlook में खोले, संशोधित और प्रबंधित किए जा सकें।

रूपांतरण तब भी आवश्यक है जब ईमेल को संग्रहीत, अनुक्रमित या उन स्टोरेज द्वारा प्रोसेस किया जाना हो जो MAPI फ़ॉर्मेट — PST/OST और OLM स्टोरेज — की मांग करते हैं।

  1. का एक इंस्टेंस बनाएं MapiConversionOptions और उसकी गुणों को कॉन्फ़िगर करें।
  2. परिवर्तित करें MailMessage ऑब्जेक्ट को एक MapiMessage ऑब्जेक्ट के साथ MapiMessage.from_mail_message() विधि, कॉन्फ़िगर किए गए विकल्प पास करते हुए।
import aspose.email as ae
from aspose.email.mapi import MapiMessage, MapiConversionOptions, OutlookMessageFormat

eml = ae.MailMessage.load(data_dir + "email.eml", ae.EmlLoadOptions())

# Create an instance of MapiConversionOptions
conversion_options = MapiConversionOptions()
conversion_options.format = OutlookMessageFormat.UNICODE          # use the Unicode format for MSG
conversion_options.preserve_embedded_message_format = True        # preserve the format of the embedded messages
conversion_options.preserve_original_addresses = True             # keep the original email addresses
conversion_options.preserve_original_dates = True                 # preserve the original dates
conversion_options.preserve_empty_dates = False                   # generate new dates if the original ones are empty
conversion_options.remove_signature = False                       # do not remove the signature
conversion_options.use_body_compression = True                    # enable the RTF body compression
conversion_options.forced_rtf_body_for_appointment = False        # disable the forced RTF body for appointments

# Convert MailMessage to MapiMessage
msg = MapiMessage.from_mail_message(eml, conversion_options)
msg.save(data_dir + "converted_out.msg")

MapiConversionOptions के उपलब्ध गुण

  • ascii_format: लौटाता है MapiConversionOptions ASCII Outlook संदेश फ़ॉर्मेट के साथ कॉन्फ़िगर किया गया। यह विकल्प तब उपयोगी है जब आपको साधारण ASCII फ़ॉर्मेट रूपांतरण चाहिए।
  • unicode_format: लौटाता है MapiConversionOptions Unicode Outlook संदेश फ़ॉर्मेट के साथ कॉन्फ़िगर किया गया। MSG फ़ाइलों में अधिक व्यापक कैरेक्टर समर्थन के लिए इस विकल्प का उपयोग करें।
  • forced_rtf_body_for_appointment: जब सेट हो True, कैलेंडर अपॉइंटमेंट्स के लिए RTF बॉडी का उपयोग अनिवार्य करता है। यह उपयोगी है यदि आप सुनिश्चित करना चाहते हैं कि संदेश कुछ मेल क्लाइंट्स के साथ संगत हो।
  • format: MSG फ़ाइल के आउटपुट फ़ॉर्मेट को निर्दिष्ट करता है। इसे सेट किया जा सकता है OutlookMessageFormat.ASCII या OutlookMessageFormat.UNICODE.
  • preserve_embedded_message_format: रूपांतरण के दौरान एम्बेडेड संदेशों के मूल EML फ़ॉर्मेट को बरकरार रखने का निर्धारण करता है। डिफ़ॉल्ट है False.
  • preserve_empty_dates: जब सेट हो True, EML से मूल सहेजने और संशोधन तिथियों को बरकरार रखता है। अन्यथा, यदि मूल तिथियां खाली हों तो नई तिथियां उत्पन्न की जाती हैं।
  • preserve_original_addresses: यदि सेट हो True, मूल ईमेल पतों को मान्यकरण के बिना बनाए रखता है। यह तब उपयोगी है जब ईमेल पते कठोर मानकों का पालन नहीं करते लेकिन उन्हें जैसा है वैसा ही रखना आवश्यक है। डिफ़ॉल्ट है False.
  • preserve_original_dates: रूपांतरण के दौरान मूल भेजने और प्राप्त करने की तिथियों को बरकरार रखता है।
  • remove_signature: नियंत्रण करता है कि यदि डिजिटल हस्ताक्षर मौजूद है तो वह रूपांतरण के दौरान संदेश से हटाया जाए। डिफ़ॉल्ट है False.
  • use_body_compression: यदि सेट हो तो RTF बॉडी संपीड़न को सक्षम करता है True. यह MSG फ़ाइल के आकार को घटाने में मदद करता है, विशेषकर बड़े संदेशों के साथ जो समृद्ध फ़ॉर्मेटिंग रखते हैं।