Работа с рассылками Outlook с использованием библиотеки Email C++
Contents
[
Hide
]
Работа с рассылками
С помощью API Aspose.Email можно создать рассылку, которая является сборищем нескольких контактов. Рассылку можно сохранить на диск в формате Outlook MSG и просмотреть/изменить, открыв её в MS Outlook.
Создание и сохранение рассылки
Следующий фрагмент кода показывает, как создать и сохранить рассылку с помощью API библиотеки C++ Email.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For complete examples and data files, please go to https://github.com/kashifiqb/Aspose.Email-for-C | |
System::String dataDir = RunExamples::GetDataDir_Outlook(); | |
System::String displayName1 = L"Sebastian Wright"; | |
System::String email1 = L"SebastianWright@dayrep.com"; | |
System::String displayName2 = L"Wichert Kroos"; | |
System::String email2 = L"WichertKroos@teleworm.us"; | |
System::String strEntryId1; | |
System::String strEntryId2; | |
System::String path = dataDir + L"CreateDistributionListInPST_out.pst"; | |
if (System::IO::File::Exists(path)) | |
{ | |
System::IO::File::Delete(path); | |
} | |
// Create distribution list from contacts | |
{ | |
System::SharedPtr<PersonalStorage> personalStorage = PersonalStorage::Create(dataDir + L"CreateDistributionListInPST_out.pst", Aspose::Email::Outlook::Pst::FileFormatVersion::Unicode); | |
// Add the contact folder to pst | |
System::SharedPtr<FolderInfo> contactFolder = personalStorage->CreatePredefinedFolder(L"Contacts", Aspose::Email::Outlook::Pst::StandardIpmFolder::Contacts); | |
// Create contacts | |
strEntryId1 = contactFolder->AddMapiMessageItem(System::MakeObject<MapiContact>(displayName1, email1)); | |
strEntryId2 = contactFolder->AddMapiMessageItem(System::MakeObject<MapiContact>(displayName2, email2)); | |
// Create distribution list on the base of the created contacts | |
System::SharedPtr<MapiDistributionListMember> member1 = System::MakeObject<MapiDistributionListMember>(displayName1, email1); | |
member1->set_EntryIdType(Aspose::Email::Outlook::MapiDistributionListEntryIdType::Contact); | |
member1->set_EntryId(System::Convert::FromBase64String(strEntryId1)); | |
System::SharedPtr<MapiDistributionListMember> member2 = System::MakeObject<MapiDistributionListMember>(displayName2, email2); | |
member2->set_EntryIdType(Aspose::Email::Outlook::MapiDistributionListEntryIdType::Contact); | |
member2->set_EntryId(System::Convert::FromBase64String(strEntryId2)); | |
System::SharedPtr<MapiDistributionListMemberCollection> members = System::MakeObject<MapiDistributionListMemberCollection>(); | |
members->Add(member1); | |
members->Add(member2); | |
System::SharedPtr<MapiDistributionList> distributionList = System::MakeObject<MapiDistributionList>(L"Contact list", members); | |
distributionList->set_Body(L"Distribution List Body"); | |
distributionList->set_Subject(L"Sample Distribution List using Aspose.Email"); | |
// Add distribution list to PST | |
contactFolder->AddMapiMessageItem(distributionList); | |
} | |
System::String path1 = dataDir + L"CreateDistributionListInPST_OneOffmembers_out.pst"; | |
if (System::IO::File::Exists(path1)) | |
{ | |
System::IO::File::Delete(path1); | |
} | |
// Create one-off distribution list members (for which no separate contacts were created) | |
{ | |
System::SharedPtr<PersonalStorage> personalStorage = PersonalStorage::Create(dataDir + L"CreateDistributionListInPST_OneOffmembers_out.pst", Aspose::Email::Outlook::Pst::FileFormatVersion::Unicode); | |
// Add the contact folder to pst | |
System::SharedPtr<FolderInfo> contactFolder = personalStorage->CreatePredefinedFolder(L"Contacts", Aspose::Email::Outlook::Pst::StandardIpmFolder::Contacts); | |
System::SharedPtr<MapiDistributionListMemberCollection> oneOffmembers = System::MakeObject<MapiDistributionListMemberCollection>(); | |
oneOffmembers->Add(System::MakeObject<MapiDistributionListMember>(L"John R. Patrick", L"JohnRPatrick@armyspy.com")); | |
oneOffmembers->Add(System::MakeObject<MapiDistributionListMember>(L"Tilly Bates", L"TillyBates@armyspy.com")); | |
System::SharedPtr<MapiDistributionList> oneOffMembersList = System::MakeObject<MapiDistributionList>(L"Simple list", oneOffmembers); | |
contactFolder->AddMapiMessageItem(oneOffMembersList); | |
} |
Чтение рассылки из PST
Следующий фрагмент кода показывает, как прочитать рассылку из PST.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For complete examples and data files, please go to https://github.com/kashifiqb/Aspose.Email-for-C | |
System::SharedPtr<MapiMessage> message = MapiMessage::FromFile(fileName); | |
System::SharedPtr<MapiDistributionList> dlist = System::DynamicCast<Aspose::Email::Outlook::MapiDistributionList>(message->ToMapiMessageItem()); |