由于该组中有更多地址,我试图从与会者那里获取电子邮件地址的详细信息,这是我的代码。
public List<Meeting> getAll(string email, string sDate, string eDate)
{
List<Meeting> res = new List<Meeting>();
ExchangeService es = new ExchangeService();
string username = Properties.Settings.Default.username;
string password = Properties.Settings.Default.password;
SecureString ssPassword = new SecureString();
foreach (char x in password)
ssPassword.AppendChar(x);
es.Credentials = new NetworkCredential(username, ssPassword);
es.Url = new Uri("https://outlook.office365.com/ews/exchange.asmx");
FolderId folderID = new FolderId(WellKnownFolderName.Calendar, "[email protected]");
DateTime startDate = DateTime.ParseExact(sDate + " 00:00:00", "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
DateTime endDate = DateTime.ParseExact(eDate + " 23:59:59", "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
CalendarView cView = new CalendarView(startDate, endDate);
//cView.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties);
FindItemsResults<Item> resultItem = es.FindItems(folderID, cView);
foreach (Item item in resultItem.Items)
{
ServiceResponseCollection<GetItemResponse> itemResponseCollection = es.BindToItems(new[] { new ItemId(item.Id.UniqueId) }, new PropertySet(BasePropertySet.FirstClassProperties));
foreach (GetItemResponse itemResponse in itemResponseCollection)
{
Appointment app = (Appointment)itemResponse.Item;
res.Add(GetClassFromAppointment(app));
}
}
return res;
}
obj.Attendees = {[email protected], [email protected], [email protected]}
“ [email protected]”包括更多电子邮件地址:ccc @ xxxx.com,ddd @ xxxx.com
如何从组中获取详细地址?
您应该只使用EWS ExpandGroup操作https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-expand-distribution-groups-by-using-ews-in-exchange-2013。例如,使用您的代码,例如
// Return the expanded group.
ExpandGroupResults myGroupMembers = es.ExpandGroup("[email protected]");
// Display the group members.
foreach (EmailAddress address in myGroupMembers.Members)
{
Console.WriteLine("Email Address: {0}", address);
}
另一种方法是因为您使用的是Office365,因此可以使用Microsoft Graph API https://docs.microsoft.com/en-us/graph/api/group-list-members?view=graph-rest-1.0&tabs=http来获取组成员。>