![](/img/trans.png)
[英]Is it possible to group together strings and count group members in an ordered Java list using streams?
[英]Is it possible to add group members to a group using Java Exchange service API for office 365 email?
我正在使用 Java API 來交換 Web 服務。 下面是我目前正在從一個組中獲取所有組成員的代碼,但我想知道我是否可以在代碼中將一個成員添加到該組中。
ExchangeService service= instance.getEgrsEmailConnection();
ExpandGroupResults myGroupMembers = service.expandGroup("testgroupone@usepa.onmicrosoft.com");
myGroupMembers.getMembers();
此代碼根據該組的電子郵件地址獲取一個組,但我想不出添加成員的方法。 任何提示都會有所幫助,謝謝。
我使用的 api 是:ews-java-api-1.3-SNAPSHOT.jar
如果 testgroupone@usepa.onmicrosoft.com 是通訊組列表(例如通用通訊組 UDG 或啟用郵件的通用安全組),則沒有 EWS 操作允許您修改這些類型的組的成員。 為此,您需要使用 LDAP 或 Exchange 命令行管理程序。 在 EWS 中,您只能修改作為郵箱或公用文件夾中存在的 Exchange 存儲對象的聯系人組。
看起來您使用的是 Office365,所以我建議使用 Graph API https://msdn.microsoft.com/en-us/library/azure/hh974478.aspx您可以使用 REST 接口輕松管理來自 Java 的組https://msdn.microsoft.com/en-us/library/azure/hh974478.aspx /azure.microsoft.com/en-us/documentation/articles/active-directory-code-samples/
干杯格倫
我轉而使用聯系人組而不是常規組,並找到了如何添加和刪除如果有人像我一樣遇到問題:
ItemView view = new ItemView(111);
//Get all items in the Contacts folder
FindItemsResults<Item> items = service.findItems(WellKnownFolderName.Contacts, view);
for(Item contactItem: items)
{
//If the item is a contactGroup then enter.
if(contactItem instanceof ContactGroup)
{
PropertySet set = new PropertySet(BasePropertySet.FirstClassProperties);
ContactGroup currentContactItem = ContactGroup.bind(service, contactItem.getId(), set);
GroupMemberCollection members = currentContactItem.getMembers();
Iterator<GroupMember> memberList = members.iterator();
ArrayList<GroupMember> removePerson = new ArrayList<GroupMember>();
ArrayList<GroupMember> addPerson = new ArrayList<GroupMember>();
while(memberList.hasNext())
{
GroupMember current = memberList.next();
removePerson.add(current);
if(current.getAddressInformation().getAddress().equalsIgnoreCase("test@gmail.com"))
{
addPerson.add(current);
}
}
for(GroupMember deletion: removePerson)
{
boolean happen = members.remove(deletion);
if(happen)
{
System.out.println("YESSS");
}
}
for(GroupMember addition: addPerson)
{
members.add(addition);
}
if(removePerson.size() > 0 || addPerson.size() > 0)
{
currentContactItem.update(ConflictResolutionMode.AlwaysOverwrite);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.