Trabajando con Listas de Distribución de Outlook usando la Biblioteca de Correo C++
Contents
[
Hide
]
Trabajando con Listas de Distribución
Es posible crear una lista de distribución utilizando la API de Aspose.Email, que es una colección de múltiples contactos. Una lista de distribución se puede guardar en disco en formato MSG de Outlook y se puede visualizar/manipular al abrirla en MS Outlook.
Crear y Guardar una Lista de Distribución
El siguiente fragmento de código te muestra cómo crear y guardar una lista de distribución con la API de la Biblioteca de Correo 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); | |
} |
Leer una Lista de Distribución desde un PST
El siguiente fragmento de código te muestra cómo leer una lista de distribución desde un 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()); |