问题
The context:
Our company has 12 coordinators. Each coordinator manages a bunch of personal contacts.
- Coordinator1 manages 409 personal contacts.
- Coordinator2 manages 216 personal contacts.
- Etc...
We have a nightly task that populates a SQL Server TABLE
holding personal contact information.
The data in the TABLE
is extracted into 12 different CSV files
which in turn is sent to each coordinator.
The coordinator has the responsibility to Import this CSV file
into his Outlook in order to keep his list of personal contacts up-to-date (yes, those personal contacts change daily).
The entire Importing of CSV file is a bit too much for most of these coordinators and the goal would be to automate this or have something that synchronizes Outlook personal contacts so that these coordinators won’t have to do this daily manual task.
What I’ve tried:
I’ve created a C# console application and I’ve added ADAL and Microsoft Graph client library NuGet packages.
I’ve correctly registered my application in Azure and obtained the Client Id
and Client Secret
.
I’ve set the appropriate Application and Delegated permissions
.
I’m able to run the application, obtain a token
and call the Microsoft Graph client.
The problem:
My problem, as of this writing, is that Microsoft Graph does not support the creation of Contact List
nor does it allow me to Add, Remove or Update personal contacts into this Contact List
.
The ability to use Groups
is not possible. Each time you add a user to a group, an email is sent to that particular user letting him know that he’s been added to a group.
In addition, that same user can remove himself from a group and we simply don’t want that.
Microsoft Graph also supports the creation of Folders
and adding people to these Folders but unfortunately, the only purpose I found for these Folders is for organizing stuff...
With Folders, I do not have the ability to send an email to a particular Folder which in turn would send an email to everyone in that Folder. That’s the purpose of the Contact List
...but, as of this writing, the API doesn’t have anything for Contact List
.
Does anyone have a better suggestion or perhaps a workaround to achieve my task?
I don’t mind having to rewrite the entire console application or even completely change the entire approach (like using Powershell)
All I care about is to not make those 12 coordinators manually Import a CSV file
anymore.
Thanks in advance.
PS: I even looked into Microsoft Flow but haven't found a Flow that could update Outlook Personal Contacts.
回答1:
At the moment neither Microsoft Graph nor the Outlook REST API supports "Contact Groups".
You can however create them programmatically using the EWS Managed API. There is a walkthrough with example C# code in How to: Create contact groups by using EWS in Exchange.
回答2:
Here is the end result if anyone cares...
static void Main(string[] args)
{
try
{
var domain = "mydomain.com";
var email = "service_account@mydomain.com";
var accountPassword = "Password1";
var emailToImpersonify = "frank_underwood@mydomain.com";
var contactGroupDisplayName = "MySuperAmazingContactGroup";
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
service.Credentials = new NetworkCredential(email, accountPassword, domain);
service.AutodiscoverUrl(email, RedirectionUrlValidationCallback);
// Make sure the account [service_account@mydomain.com] is a member of the ApplicationImpersonation admin role.
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, emailToImpersonify);
// Prior to creating the ContactGroup, check and delete any pre-existing ContactGroup
SearchFilter sfSearch = new SearchFilter.IsEqualTo(ContactGroupSchema.DisplayName, contactGroupDisplayName);
FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Contacts, sfSearch, new ItemView(int.MaxValue));
if (results != null)
{
foreach (Item item in results)
item.Delete(DeleteMode.HardDelete);
}
// Create the new ContactGroup with a few members
ContactGroup newContactGroup = new ContactGroup(service);
newContactGroup.DisplayName = contactGroupDisplayName;
newContactGroup.Members.Add(new GroupMember("user1@contoso.com"));
newContactGroup.Members.Add(new GroupMember("user2@contoso.com"));
newContactGroup.Save();
}
catch (Exception ex)
{
throw ex;
}
}
来源:https://stackoverflow.com/questions/45303588/update-office365-personal-contacts