โหลดและบันทึกข้อความอีเมลโดยใช้ Aspose.Email for C++
Aspose.Email for C++ ให้ตัวเลือกที่ยืดหยุ่นในการโหลด, บันทึก, และแปลงข้อความอีเมลในหลายรูปแบบ รวมถึง EML, MSG, MHTML, และ HTML นอกจากนี้คุณยังสามารถกำหนดตัวเลือกการโหลดและบันทึกเพื่อจัดการการเข้ารหัส, ไฟล์แนบ, และความต้องการรูปแบบ
ตัวอย่างในบทความนี้ใช้ส่วนหัวและเนมสเปซต่อไปนี้:
#include <MailMessage.h>
#include <EmlLoadOptions.h>
#include <EmlxLoadOptions.h>
#include <HtmlLoadOptions.h>
#include <MhtmlLoadOptions.h>
#include <MsgLoadOptions.h>
#include <TnefLoadOptions.h>
#include <SaveOptions.h>
#include <EmlSaveOptions.h>
#include <MsgSaveOptions.h>
#include <MhtSaveOptions.h>
#include <HtmlSaveOptions.h>
#include <MailMessageSaveType.h>
#include <MhtFormatOptions.h>
#include <HtmlFormatOptions.h>
#include <MhtTemplateName.h>
#include <system/collections/specialized/string_dictionary.h>
#include <ResourceRenderingMode.h>
#include <FileCompatibilityMode.h>
#include <AttachmentCollection.h>
#include <Attachment.h>
#include <Mapi/MapiMessage.h>
#include <Mapi/MapiConversionOptions.h>
#include <Mapi/OutlookMessageFormat.h>
#include <Tools/FileFormat/FileFormatUtil.h>
#include <Tools/FileFormat/FileFormatInfo.h>
#include <Tools/FileFormat/FileFormatType.h>
#include <system/io/file.h>
#include <system/io/directory.h>
#include <system/io/file_info.h>
#include <system/text/encoding.h>
#include <system/object_ext.h>
#include <system/convert.h>
#include <system/timezone_info.h>
#include <system/timespan.h>
using namespace System;
using namespace Aspose::Email;
using namespace Aspose::Email::Mapi;
using namespace Aspose::Email::Tools;
โหลดข้อความด้วยตัวเลือกการโหลดที่กำหนดเอง
นี้ MailMessage คลาสโหลดข้อความในรูปแบบ EML, EMLX, MSG, MHTML, HTML และ TNEF. ทุกรูปแบบอินพุตมีคลาสลูกของ LoadOptions, และออบเจกต์จะถูกส่งไปยัง MailMessage::Load พร้อมกับชื่อไฟล์หรือสตรีม. คลาสฐานจะให้การตั้งค่า 3 อย่างกับทั้งหมด - PreferredTextEncoding สำหรับข้อความที่ไม่มี charset ที่ระบุ, PreserveEmbeddedMessageFormat สำหรับรายการที่แนบเป็นข้อความ, และ RemoveSignature - ในขณะที่แต่ละรูปแบบเพิ่มของมันเอง:
| Class | Format | Additional settings | | — | — | — | | EmlLoadOptions | EML | PreserveTnefAttachments |
| EmlxLoadOptions | EMLX (Apple Mail) | - | | HtmlLoadOptions | HTML | PathToResources, ShouldAddPlainTextView |
| MhtmlLoadOptions | MHTML | PreserveTnefAttachments |
| MsgLoadOptions | Outlook MSG | KeepOriginalEmailAddresses, PreserveRtfContent, PreserveTnefAttachments, เวลาจำกัด |
| TnefLoadOptions | raw TNEF (winmail.dat) | - |
// EML
SharedPtr<EmlLoadOptions> emlOptions = MakeObject<EmlLoadOptions>();
emlOptions->set_PreferredTextEncoding(System::Text::Encoding::get_UTF8()); // encoding for subject and body
emlOptions->set_PreserveEmbeddedMessageFormat(true); // keep embedded items as they are
emlOptions->set_PreserveTnefAttachments(true); // keep winmail.dat parts
emlOptions->set_RemoveSignature(false); // keep the S/MIME signature
SharedPtr<MailMessage> eml = MailMessage::Load(u"sample.eml", emlOptions);
// EMLX (Apple Mail)
SharedPtr<EmlxLoadOptions> emlxOptions = MakeObject<EmlxLoadOptions>();
emlxOptions->set_PreferredTextEncoding(System::Text::Encoding::get_UTF8());
emlxOptions->set_PreserveEmbeddedMessageFormat(true);
SharedPtr<MailMessage> emlx = MailMessage::Load(u"sample.emlx", emlxOptions);
// HTML
SharedPtr<HtmlLoadOptions> htmlOptions = MakeObject<HtmlLoadOptions>();
htmlOptions->set_PathToResources(u"."); // where the referenced images live
htmlOptions->set_ShouldAddPlainTextView(true); // add a text/plain alternative
SharedPtr<MailMessage> fromHtml = MailMessage::Load(u"body_content.html", htmlOptions);
// MHTML
SharedPtr<MhtmlLoadOptions> mhtmlOptions = MakeObject<MhtmlLoadOptions>();
mhtmlOptions->set_PreserveTnefAttachments(true);
SharedPtr<MailMessage> fromMhtml = MailMessage::Load(u"sample.mhtml", mhtmlOptions);
// MSG
SharedPtr<MsgLoadOptions> msgOptions = MakeObject<MsgLoadOptions>();
msgOptions->set_KeepOriginalEmailAddresses(true); // do not rewrite Exchange addresses
msgOptions->set_PreserveRtfContent(true); // keep the RTF body
msgOptions->set_Timeout(5000); // formatting time limit, milliseconds
SharedPtr<MailMessage> fromMsg = MailMessage::Load(u"sample.msg", msgOptions);
// TNEF - a raw winmail.dat file, not a message that contains one
SharedPtr<TnefLoadOptions> tnefOptions = MakeObject<TnefLoadOptions>();
tnefOptions->set_PreferredTextEncoding(System::Text::Encoding::get_UTF8());
SharedPtr<MailMessage> fromTnef = MailMessage::Load(u"winmail.dat", tnefOptions);
Console::WriteLine(u"Subjects: " + eml->get_Subject() + u" | " + emlx->get_Subject() +
u" | " + fromMsg->get_Subject() + u" | " + fromTnef->get_Subject());
winmail.dat ไฟล์. ข้อความปกติที่เพียงแค่มีไฟล์แนบเช่นนี้จะถูกโหลดด้วยตัวเลือกของรูปแบบของมันเอง, ตามที่แสดงใน ทำงานกับไฟล์แนบ TNEF.
รักษารูปแบบของข้อความที่ฝังอยู่
รายการที่แนบเป็นข้อความสามารถจัดเก็บเป็น MSG หรือ EML. กับ PreserveEmbeddedMessageFormat ไฟล์แนบจะคงรูปแบบที่มีในไฟล์ต้นฉบับแทนการแปลง:
SharedPtr<EmlLoadOptions> options = MakeObject<EmlLoadOptions>();
options->set_PreserveEmbeddedMessageFormat(true);
SharedPtr<MailMessage> mail = MailMessage::Load(u"tnefWithMsgInside.eml", options);
// the embedded item keeps the format it had in the source message
FileFormatType fileFormat = FileFormatUtil::DetectFileFormat(
mail->get_Attachments()->idx_get(0)->get_ContentStream())->get_FileFormatType();
Console::WriteLine(u"Embedded message file format: " + ObjectExt::ToString(fileFormat));
ข้อความที่ลงลายเซ็นและการตรวจจับรูปแบบไฟล์
ลายเซ็นจะถูกเก็บไว้ขณะวิเคราะห์ข้อความ. RemoveSignature ขอให้ไลบรารีละทิ้งมัน, และ FileFormatUtil::DetectFileFormat รายงานว่าสิ่งที่ไฟล์เป็นอะไรก่อนโหลด - มีประโยชน์เมื่อส่วนขยายไฟล์ไม่เชื่อถือได้.
// a signature is kept by default
SharedPtr<MailMessage> signedMessage = MailMessage::Load(u"signed.eml");
Console::WriteLine(u"IsSigned: " + Convert::ToString(signedMessage->get_IsSigned()) +
u", IsEncrypted: " + Convert::ToString(signedMessage->get_IsEncrypted()));
// RemoveSignature strips it while the message is parsed
SharedPtr<EmlLoadOptions> options = MakeObject<EmlLoadOptions>();
options->set_RemoveSignature(true);
SharedPtr<MailMessage> unsigned_ = MailMessage::Load(u"signed.eml", options);
Console::WriteLine(u"After RemoveSignature: " + Convert::ToString(unsigned_->get_IsSigned()));
// the format of a file can be detected before it is loaded
SharedPtr<FileFormatInfo> info = FileFormatUtil::DetectFileFormat(u"Message.msg");
Console::WriteLine(u"The message format is: " + ObjectExt::ToString(info->get_FileFormatType()));
บันทึกข้อความอีเมลในรูปแบบต่าง ๆ
Aspose.Email for C++ ทำให้สามารถแปลงข้อความระหว่างรูปแบบเช่น EML, MSG, MHTML, และ HTML นักพัฒนาสามารถใช้ SaveOptions ลำดับชั้นของคลาสเพื่อระบุพารามิเตอร์การบันทึกระดับสูง รวมถึงการเข้ารหัส, ไฟล์แนบ TNEF, และการรักษาขอบเขต
ตัวเลือกการบันทึกที่มีรวมถึง:
EmlSaveOptionsMsgSaveOptionsMhtSaveOptionsHtmlSaveOptions
บันทึกอีเมลเป็น EML
MailMessage::Save กับ SaveOptions::get_DefaultEml เขียนข้อความเป็นไฟล์ EML. ตัวอย่างโหลดข้อความ EML และบันทึกกลับในรูปแบบเดียวกัน.
SharedPtr<MailMessage> mailMessage = MailMessage::Load(u"Attachments.eml");
mailMessage->Save(u"Attachments_copy.eml", SaveOptions::get_DefaultEml());
Console::WriteLine(u"Attachments in the copy: " + Convert::ToString(MailMessage::Load(u"Attachments_copy.eml")->get_Attachments()->get_Count()));
รักษาขอบเขต EML ดั้งเดิม
ขอบเขต MIME แยกส่วนของข้อความออกจากกัน. เมื่อโหลดข้อความ EML แล้วบันทึกกลับเป็น EML, ขอบเขตของต้นฉบับจะถูกเก็บไว้, ดังนั้นไฟล์ที่บันทึกสามารถเปรียบเทียบกับต้นฉบับได้ส่วนต่อส่วน; ไม่จำเป็นต้องมีตัวเลือกเพิ่มเติม. ขอบเขตของคุณเองตั้งค่าด้วยเทมเพลต, ตามที่แสดงใน ปรับแต่งขอบเขต MIME.
SharedPtr<MailMessage> mailMessage = MailMessage::Load(u"Attachments.eml");
SharedPtr<EmlSaveOptions> emlSaveOptions = MakeObject<EmlSaveOptions>(MailMessageSaveType::get_EmlFormat());
mailMessage->Save(u"PreservedBoundaries.eml", emlSaveOptions);
// the first boundary of the source file and of the saved file
auto firstBoundary = [](String path)
{
String text = IO::File::ReadAllText(path);
int32_t start = text.IndexOf(u"boundary=\"") + 10;
return text.Substring(start, text.IndexOf(u'"', start) - start);
};
Console::WriteLine(u"Source: " + firstBoundary(u"Attachments.eml"));
Console::WriteLine(u"Saved: " + firstBoundary(u"PreservedBoundaries.eml"));
รักษาไฟล์แนบ TNEF ใน EML
ข้อความที่มาพร้อมส่วน TNEF (winmail.dat) ปกติจะถูกเขียนใหม่เป็น MIME ธรรมดาเมื่อบันทึก. การตั้งค่า FileCompatibilityMode::PreserveTnefAttachments บน EmlSaveOptions เก็บส่วน TNEF ไว้เช่นเดิม, เพื่อให้ไคลเอนท์ที่พึ่งพา (โดยเฉพาะ Outlook) ยังคงเข้าถึงข้อมูลได้. รายละเอียดเพิ่มเติมเกี่ยวกับข้อความ TNEF อยู่ใน ทำงานกับไฟล์แนบ TNEF.
SharedPtr<MailMessage> mailMessage = MailMessage::Load(u"tnefEml1.eml");
SharedPtr<EmlSaveOptions> emlSaveOptions = MakeObject<EmlSaveOptions>(MailMessageSaveType::get_EmlFormat());
emlSaveOptions->set_FileCompatibilityMode(FileCompatibilityMode::PreserveTnefAttachments);
mailMessage->Save(u"PreservedTnef.eml", emlSaveOptions);
// the TNEF part is still there
SharedPtr<EmlLoadOptions> loadOptions = MakeObject<EmlLoadOptions>();
loadOptions->set_PreserveTnefAttachments(true);
for (SharedPtr<Attachment> attachment : MailMessage::Load(u"PreservedTnef.eml", loadOptions)->get_Attachments())
{
Console::WriteLine(attachment->get_Name() + u" - TNEF: " + Convert::ToString(attachment->get_IsTnef()));
}
แปลง EML เป็น MSG
ไฟล์ EML จะกลายเป็นไฟล์ Outlook MSG เมื่อบันทึกด้วย SaveOptions::get_DefaultMsgUnicode - รูปแบบ MSG Unicode ที่ใช้โดย Outlook รุ่นล่าสุด - หรือด้วย get_DefaultMsg สำหรับรูปแบบ ANSI เก่า.
SharedPtr<MailMessage> eml = MailMessage::Load(u"Message.eml");
eml->Save(u"FromEml.msg", SaveOptions::get_DefaultMsgUnicode());
Console::WriteLine(u"Saved as MSG: " + MapiMessage::Load(u"FromEml.msg")->get_Subject());
บันทึกเป็น MHTML
SaveOptions::get_DefaultMhtml สร้างไฟล์ MHTML เดียวที่เบราว์เซอร์สามารถแสดงได้, โดยหัวเรื่องข้อความถูกเขียนเหนือเนื้อหาและภาพถูกฝัง.
SharedPtr<MailMessage> eml = MailMessage::Load(u"Message.eml");
eml->Save(u"FromEml.mhtml", SaveOptions::get_DefaultMhtml());
ส่งออกเป็น MHT พร้อมโซนเวลาที่กำหนดเอง
วันที่ที่เขียนลงในหัวเรื่องของหน้า MHTML จะถูกแสดงในโซนเวลาที่กำหนดโดย TimeZoneOffset. ตั้งค่าเป็นค่าออฟเซ็ตของระบบท้องถิ่นเพื่อแสดงเวลาในท้องถิ่น, หรือเป็นออฟเซ็ตคงที่ใดๆ; MhtFormatOptions::WriteHeader ทำให้แน่ใจว่าหัวเรื่องที่มีวันที่ถูกเขียน.
SharedPtr<MailMessage> eml = MailMessage::Load(u"Message.eml");
// the offset of the local system ...
eml->set_TimeZoneOffset(TimeZoneInfo::get_Local()->GetUtcOffset(DateTime::get_Now()));
// ... or any fixed offset, here UTC-08:00
eml->set_TimeZoneOffset(TimeSpan(-8, 0, 0));
SharedPtr<MhtSaveOptions> options = MakeObject<MhtSaveOptions>();
options->set_MhtFormatOptions(MhtFormatOptions::WriteHeader);
eml->Save(u"CustomTimeZone.mhtml", options);
ส่งออกอีเมลเป็น EML
ข้อความที่โหลดจากรูปแบบอื่นจะถูกส่งออกเป็น EML แบบเดียวกัน. ตัวอย่างแปลงไฟล์ Outlook MSG.
SharedPtr<MailMessage> msg = MailMessage::Load(u"Message.msg");
msg->Save(u"ExportedFromMsg.eml", SaveOptions::get_DefaultEml());
Console::WriteLine(u"Exported: " + MailMessage::Load(u"ExportedFromMsg.eml")->get_Subject());
ปรับแต่งขอบเขต MIME
ขอบเขตของข้อความต้นฉบับจะคงไว้เมื่อโหลดไฟล์ EML แล้วบันทึกกลับ. หากต้องการสร้างตามรูปแบบของคุณเอง, ตั้งค่า BoundariesTemplate บน EmlSaveOptions. รองรับตัวแทรกสองตำแหน่ง: {#} สำหรับหมายเลขขอบเขตและ {guid} สำหรับ GUID ที่สร้างขึ้น.
SharedPtr<MailMessage> mailMessage = MailMessage::Load(u"Attachments.eml");
SharedPtr<EmlSaveOptions> emlSaveOptions = MakeObject<EmlSaveOptions>(MailMessageSaveType::get_EmlFormat());
// {#} is replaced with the boundary number, {guid} with a generated GUID
emlSaveOptions->set_BoundariesTemplate(u"boundary_{#}_{guid}");
mailMessage->Save(u"CustomBoundaries.eml", emlSaveOptions);
Console::WriteLine(IO::File::ReadAllText(u"CustomBoundaries.eml").Substring(0, 300));
เมื่อรูปแบบเป้าหมายคือ MHTML, ขอบเขตของข้อความต้นฉบับจะถูกเก็บไว้ด้วย MhtSaveOptions::PreserveOriginalBoundaries.
รักษาวันที่ต้นฉบับและบันทึกเป็นเทมเพลต
โดยค่าเริ่มต้นการแปลงเป็น MSG จะติดเวลา ณ ขณะนั้น. PreserveOriginalDates เก็บวันที่ของข้อความต้นฉบับแทน. รูปแบบเทมเพลต Outlook (.oft) มีชุดตัวเลือกสำเร็จรูปของมันเอง, SaveOptions::DefaultOft.
SharedPtr<MailMessage> eml = MailMessage::Load(u"Attachments.eml");
// keep the dates of the source message instead of stamping the current time
SharedPtr<MsgSaveOptions> msgSaveOptions = MakeObject<MsgSaveOptions>(MailMessageSaveType::get_OutlookMessageFormatUnicode());
msgSaveOptions->set_PreserveOriginalDates(true);
eml->Save(u"PreservedDates.msg", msgSaveOptions);
// an Outlook template (.oft) is written with the dedicated save type
eml->Save(u"AsTemplate.oft", SaveOptions::get_DefaultOft());
Console::WriteLine(u"msg: " + Convert::ToString(MakeObject<IO::FileInfo>(u"PreservedDates.msg")->get_Length()) +
u" bytes, oft: " + Convert::ToString(MakeObject<IO::FileInfo>(u"AsTemplate.oft")->get_Length()) + u" bytes");
ตัวเลือกผลลัพธ์ MHTML
MhtSaveOptions กำหนดรูปร่างของผลลัพธ์ MHTML. MhtFormatOptions เป็นการระบุค่าสถานะที่ตัดสินว่าสิ่งใดจะถูกเรนเดอร์: WriteHeader เขียนบล็อกหัวเรื่องเหนือเนื้อหา, RenderCalendarEvent เพิ่มรายละเอียดของการประชุม, RenderVCardInfo เช่นของผู้ติดต่อ, RenderTaskFields เช่นของงาน, และ WriteComplete...EmailAddress สมาชิกพิมพ์ที่อยู่เต็มแทนชื่อที่แสดง. แถวหัวข้อแต่ละบรรทัดจะถูกจัดรูปแบบผ่านเทมเพลตที่ตั้งชื่อโดย MhtTemplateName.
SharedPtr<MailMessage> msg = MailMessage::Load(u"Meeting_with_Recurring_Occurrences.msg");
// render the calendar event together with the header block
SharedPtr<MhtSaveOptions> options = MakeObject<MhtSaveOptions>();
options->set_MhtFormatOptions(MhtFormatOptions::WriteHeader | MhtFormatOptions::RenderCalendarEvent);
// the header lines can be reformatted through their templates
options->get_FormatTemplates()->idx_set(MhtTemplateName::Start,
u"<span class='headerLineTitle'>Start:</span><span class='headerLineText'>{0}</span><br/>");
msg->Save(u"MeetingWithEvent.mhtml", options);
// leave the inline images out of the output
SharedPtr<MhtSaveOptions> withoutImages = MakeObject<MhtSaveOptions>();
withoutImages->set_SkipInlineImages(true);
SharedPtr<MailMessage> eml = MailMessage::Load(u"EmailWithAttachEmbedded.eml");
eml->Save(u"NoInlineImages.mhtml", withoutImages);
// keep the MIME boundaries of the source message
SharedPtr<MhtSaveOptions> keepBoundaries = MakeObject<MhtSaveOptions>();
keepBoundaries->set_PreserveOriginalBoundaries(true);
eml->Save(u"OriginalBoundaries.mhtml", keepBoundaries);
ปรับฟอนต์ของผลลัพธ์
บล็อก CSS ที่ไลบรารีเขียนลงใน MHTML มีให้เป็น CssStyles สตริงและสามารถขยายได้ก่อนบันทึก:
SharedPtr<MailMessage> eml = MailMessage::Load(u"Attachments.eml");
SharedPtr<MhtSaveOptions> options = SaveOptions::get_DefaultMhtml();
// the CSS block that Aspose.Email writes into the MHTML can be extended
int32_t cssInsertPos = options->get_CssStyles().LastIndexOf(u"</style>");
options->set_CssStyles(options->get_CssStyles().Insert(cssInsertPos, u".PlainText{ font-family: sans-serif; }"));
eml->Save(u"CustomFont.mhtml", options);
ควบคุมวิธีการเขียนทรัพยากรลงใน HTML
เมื่อข้อความถูกส่งออกเป็น HTML, ภาพในบรรทัดจะถูกฝังเป็นข้อมูล base64 โดยค่าเริ่มต้น. ResourceRenderingMode เปลี่ยนสิ่งนั้น: SaveToFile เขียนทุกทรัพยากรลงในโฟลเดอร์ข้างไฟล์ HTML แล้วใส่เส้นทางลงใน src แอตทริบิวต์, SubstituteFromFile แทนที่ทรัพยากรด้วยไอคอนของคุณเอง, และ None ละทิ้งทรัพยากรทั้งหมด. PathToHtmlFile บอกไลบรารีว่าตำแหน่งโฟลเดอร์นั้นอยู่ที่ไหน, และ UseRelativePathToResources เขียนเส้นทางสัมพันธ์ลงใน markup.
SharedPtr<MailMessage> msg = MailMessage::Load(u"EmailWithAttachEmbedded.eml");
SharedPtr<HtmlSaveOptions> options = MakeObject<HtmlSaveOptions>();
// write the inline images next to the HTML file instead of embedding them as base64
options->set_ResourceRenderingMode(ResourceRenderingMode::SaveToFile);
options->set_PathToHtmlFile(u"HtmlExport.html");
options->set_UseRelativePathToResources(true);
// include the header block in the body
options->set_HtmlFormatOptions(HtmlFormatOptions::WriteHeader);
msg->Save(u"HtmlExport.html", options);
for (String f : IO::Directory::GetFiles(u".", u"HtmlExport*"))
{
Console::WriteLine(IO::Path::GetFileName(f));
}
แปลง MailMessage เป็น MapiMessage
ที่เก็บข้อมูล PST และ OLM, รวมถึง Outlook เอง, ทำงานกับรายการ MAPI. MapiMessage::FromMailMessage ทำการแปลง, และ MapiConversionOptions ควบคุมรายละเอียดของมัน:
| Property | Meaning | | — | — | | Format | OutlookMessageFormat Unicode หรือ Ascii. |
| PreserveOriginalDates | เก็บวันที่ของข้อความต้นฉบับ. | | PreserveOriginalAddresses | ไม่เขียนที่อยู่ใหม่เป็นรูปแบบ Exchange. | | PreserveEmbeddedMessageFormat | เก็บข้อความที่แนบไว้ในรูปแบบของมันเอง. | | UseBodyCompression | จัดเก็บเนื้อหา RTF แบบบีบอัด. | | RemoveSignature | ลบลายเซ็น S/MIME ระหว่างการแปลง. | | ForcedRtfBodyForAppointment | เขียนเนื้อหา RTF เสมอสำหรับนัดหมาย. |
ASCIIFormat และ UnicodeFormat คืนค่าชุดตัวเลือกสำเร็จรูปสำหรับสองรูปแบบ Outlook.
SharedPtr<MailMessage> eml = MailMessage::Load(u"Attachments.eml");
SharedPtr<MapiConversionOptions> options = MakeObject<MapiConversionOptions>();
options->set_Format(OutlookMessageFormat::Unicode); // Unicode or Ascii
options->set_PreserveOriginalDates(true); // keep the dates of the source message
options->set_PreserveOriginalAddresses(true); // do not rewrite the addresses
options->set_PreserveEmbeddedMessageFormat(true); // keep embedded items in their own format
options->set_UseBodyCompression(true); // compress the RTF body
SharedPtr<MapiMessage> mapi = MapiMessage::FromMailMessage(eml, options);
mapi->Save(u"ConvertedWithOptions.msg");
// ready-made option sets for the two Outlook formats
SharedPtr<MapiMessage> unicode = MapiMessage::FromMailMessage(eml, MapiConversionOptions::get_UnicodeFormat());
SharedPtr<MapiMessage> ascii = MapiMessage::FromMailMessage(eml, MapiConversionOptions::get_ASCIIFormat());
Console::WriteLine(u"Unicode body: " + Convert::ToString(unicode->get_Body().get_Length()) +
u", ASCII body: " + Convert::ToString(ascii->get_Body().get_Length()));