MSG를 다른 형식으로 변환
MSG는 단일 Outlook 항목의 파일 형식입니다 - 이메일뿐 아니라 약속, 연락처, 작업도 포함합니다. Aspose.Email for C++는 이를 다음으로 엽니다 MapiMessage::Load, 이는 항목의 모든 MAPI 속성을 유지하거나 MailMessage::Load, 이메일을 MIME 형태로 변환합니다. 어느 것을 사용할지는 대상에 따라 다릅니다: MIME 기반 형식은 둘 중 하나에서 시작하고, 캘린더와 연락처 내보내기는 MAPI 항목이 필요합니다.
이 문서의 샘플은 다음 헤더와 네임스페이스를 사용합니다:
#include <MailMessage.h>
#include <SaveOptions.h>
#include <EmlSaveOptions.h>
#include <HtmlSaveOptions.h>
#include <MhtSaveOptions.h>
#include <MsgSaveOptions.h>
#include <Calendar/AppointmentSaveFormat.h>
#include <Mapi/MapiMessage.h>
#include <Mapi/MapiItemType.h>
#include <Mapi/MapiCalendar.h>
#include <Mapi/MapiContact.h>
#include <Mapi/MapiContactNamePropertySet.h>
#include <Mapi/MailConversionOptions.h>
#include <Mapi/ContactSaveFormat.h>
#include <Storage/Mbox/MboxrdStorageWriter.h>
#include <Storage/Mbox/MboxSaveOptions.h>
#include <Storage/Pst/PersonalStorage.h>
#include <Storage/Pst/FileFormatVersion.h>
#include <Storage/Pst/FolderInfo.h>
#include <Storage/Pst/StandardIpmFolder.h>
#include <system/convert.h>
using namespace System;
using namespace Aspose::Email;
using namespace Aspose::Email::Calendar;
using namespace Aspose::Email::Mapi;
using namespace Aspose::Email::Storage::Mbox;
using namespace Aspose::Email::Storage::Pst;
MSG를 EML 및 EMLX로 변환
MapiMessage::Save 동일한 SaveOptions 다음과 같이 MailMessage, 따라서 하나의 호출로 MSG 파일이 EML 또는 Apple Mail EMLX 파일이 됩니다.
SharedPtr<MapiMessage> msg = MapiMessage::Load(u"sample.msg");
msg->Save(u"from-msg.eml", SaveOptions::get_DefaultEml());
msg->Save(u"from-msg.emlx", SaveOptions::get_DefaultEmlx());
변환을 세밀하게 조정해야 할 경우, 항목을 다음으로 변환합니다 MailMessage 먼저 ToMailMessage. MailConversionOptions 그런 다음 예를 들어 항목의 RTF 본문을 유지할지 여부를 결정합니다.
SharedPtr<MapiMessage> msg = MapiMessage::Load(u"MSG_file_with_RTF_Formatting.msg");
SharedPtr<MailConversionOptions> options = MakeObject<MailConversionOptions>();
options->set_PreserveRtfContent(true); // keep the RTF body of the Outlook item
SharedPtr<MailMessage> mail = msg->ToMailMessage(options);
mail->Save(u"from-msg-with-rtf.eml", SaveOptions::get_DefaultEml());
MSG를 HTML 및 MHTML로 변환
같은 Save 호출은 웹 페이지를 생성합니다. HTML은 별도의 리소스 폴더가 있거나 임베디드 리소스를 제공하는데, 이는 HtmlSaveOptions; MHTML은 모든 것을 하나의 파일에 압축합니다.
SharedPtr<MapiMessage> msg = MapiMessage::Load(u"sample.msg");
msg->Save(u"from-msg.html", SaveOptions::get_DefaultHtml());
msg->Save(u"from-msg.mhtml", SaveOptions::get_DefaultMhtml());
MSG를 OFT로 변환
SaveAsTemplate 항목을 Outlook 템플릿으로 씁니다: Outlook에서 열면 같은 내용의 새 메시지가 시작됩니다.
SharedPtr<MapiMessage> msg = MapiMessage::Load(u"sample.msg");
msg->SaveAsTemplate(u"from-msg.oft");
Console::WriteLine(u"Template: " + Convert::ToString(MapiMessage::Load(u"from-msg.oft")->get_IsTemplate()));
캘린더 MSG를 ICS로 변환
Outlook에서 저장된 약속은 항목이 MapiCalendar. 확인 SupportedType, 항목을 다음으로 변환합니다 ToMapiMessageItem, 그리고 다음으로 저장합니다 AppointmentSaveFormat::Ics.
SharedPtr<MapiMessage> msg = MapiMessage::Load(u"Test_Meeting.msg");
if (msg->get_SupportedType() == MapiItemType::Calendar)
{
SharedPtr<MapiCalendar> calendar = DynamicCast<MapiCalendar>(msg->ToMapiMessageItem());
calendar->Save(u"from-msg.ics", AppointmentSaveFormat::Ics);
Console::WriteLine(u"Exported: " + calendar->get_Subject());
}
연락처 MSG를 VCF로 변환
Outlook에서 저장된 연락처는 MapiContact; ContactSaveFormat VCard vCard 파일로 씁니다.
SharedPtr<MapiMessage> msg = MapiMessage::Load(u"Contact.msg");
if (msg->get_SupportedType() == MapiItemType::Contact)
{
SharedPtr<MapiContact> contact = DynamicCast<MapiContact>(msg->ToMapiMessageItem());
contact->Save(u"from-msg.vcf", ContactSaveFormat::VCard);
Console::WriteLine(u"Exported: " + contact->get_NameInfo()->get_DisplayName());
}
MSG 메시지를 MBOX 파일에 추가
MBOX는 MIME 메시지를 저장하므로 각 MSG 항목은 다음으로 변환됩니다 ToMailMessage 이전 MboxrdStorageWriter::WriteMessage 추가합니다.
SharedPtr<MboxrdStorageWriter> writer = MakeObject<MboxrdStorageWriter>(u"from-msg.mbox", MakeObject<MboxSaveOptions>());
for (String file : { String(u"sample.msg"), String(u"Message.msg") })
{
SharedPtr<MapiMessage> msg = MapiMessage::Load(file);
writer->WriteMessage(msg->ToMailMessage(MakeObject<MailConversionOptions>()));
}
writer->Dispose();
MSG 항목을 PST 파일에 추가
PST는 MAPI 항목을 직접 저장하므로, 로드된 MapiMessage 폴더에 그대로 들어갑니다. 각 항목 유형을 해당 폴더에 넣어야 합니다 - 이메일은 메일 폴더에, 약속은 캘린더 폴더에, 연락처는 연락처 폴더에 - Outlook이 올바른 뷰로 표시하도록.
SharedPtr<PersonalStorage> pst = PersonalStorage::Create(u"from-msg.pst", FileFormatVersion::Unicode);
SharedPtr<FolderInfo> inbox = pst->CreatePredefinedFolder(u"Inbox", StandardIpmFolder::Inbox);
SharedPtr<FolderInfo> calendar = pst->CreatePredefinedFolder(u"Calendar", StandardIpmFolder::Appointments);
SharedPtr<FolderInfo> contacts = pst->CreatePredefinedFolder(u"Contacts", StandardIpmFolder::Contacts);
for (String file : { String(u"sample.msg"), String(u"Test_Meeting.msg"), String(u"Contact.msg") })
{
SharedPtr<MapiMessage> msg = MapiMessage::Load(file);
switch (msg->get_SupportedType())
{
case MapiItemType::Calendar:
calendar->AddMessage(msg);
break;
case MapiItemType::Contact:
contacts->AddMessage(msg);
break;
default:
inbox->AddMessage(msg);
break;
}
}
Console::WriteLine(u"Inbox: " + Convert::ToString(inbox->get_ContentCount()) +
u", Calendar: " + Convert::ToString(calendar->get_ContentCount()) +
u", Contacts: " + Convert::ToString(contacts->get_ContentCount()));
pst->Dispose();