Trabalhando com Listas de Distribuição do Outlook usando a Biblioteca de Email C++
Contents
[
Hide
]
Trabalhando com Listas de Distribuição
É possível criar uma lista de distribuição usando a API Aspose.Email, que é uma coletânea de múltiplos contatos. Uma lista de distribuição pode ser salva em disco no formato MSG do Outlook e pode ser visualizada/manipulada ao ser aberta no MS Outlook.
Criando e Salvando uma Lista de Distribuição
O seguinte trecho de código mostra como criar e salvar uma lista de distribuição com a API da Biblioteca de Email C++.
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); | |
} |
Lendo uma Lista de Distribuição de um PST
O seguinte trecho de código mostra como ler uma lista de distribuição de um 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()); |