本文整理汇总了C#中ExchangeService.LoadPropertiesForItems方法的典型用法代码示例。如果您正苦于以下问题:C# ExchangeService.LoadPropertiesForItems方法的具体用法?C# ExchangeService.LoadPropertiesForItems怎么用?C# ExchangeService.LoadPropertiesForItems使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExchangeService
的用法示例。
在下文中一共展示了ExchangeService.LoadPropertiesForItems方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MoveMailToDeletedFolder
public static void MoveMailToDeletedFolder()
{
OApplicationSetting applicationSetting = OApplicationSetting.Current;
ServicePointManager.ServerCertificateValidationCallback =
delegate(Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
// trust any certificate
return true;
};
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new NetworkCredential(applicationSetting.EmailUserName, applicationSetting.EmailPassword, applicationSetting.EmailDomain);
service.Url = new Uri(applicationSetting.EmailExchangeWebServiceUrl);
FindItemsResults<Item> findResults =
service.FindItems(WellKnownFolderName.Inbox, new ItemView(10));
if (findResults.TotalCount > 0)
{
service.LoadPropertiesForItems(findResults.Items, PropertySet.FirstClassProperties);
foreach (Item item in findResults.Items)
{
item.Delete(DeleteMode.MoveToDeletedItems);
}
}
}
示例2: getMail
private static void getMail()
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
service.Credentials = new System.Net.NetworkCredential( "neville.kuyt", "0bvious!", "EMEA" );
service.AutodiscoverUrl("[email protected]");
log.Debug("Connecting to email server" + service.ServerInfo);
FindItemsResults<Item> findTravelResults = service.FindItems(WellKnownFolderName.Inbox, "System.Message.FromAddress:=*@chamberstravel.com AND System.Subject:Ticketed itinerary for*", new ItemView(10));
service.LoadPropertiesForItems(findTravelResults, PropertySet.FirstClassProperties);
log.Debug("Found " + findTravelResults.Items.Count + " mails");
foreach (Item item in findTravelResults.Items)
{
log.Debug(item.Subject);
parseMail(item);
}
}
示例3: SearchSharedMailBoxes
private List<MailItem> SearchSharedMailBoxes(ExchangeService service,
ItemView view,
SearchFilter.SearchFilterCollection searchFilters,
MailSearchContainerNameList mailBoxNames,
string mailDomain,
string searchTerm)
{
var result = new List<MailItem>();
if (mailBoxNames == null
|| mailBoxNames.Count <= 0 ) return result;
foreach (var mailBoxName in mailBoxNames)
{
try
{
var fullyQualifiedMailboxName = String.Format("{0}@{1}", mailBoxName, mailDomain);
Mailbox mb = new Mailbox(fullyQualifiedMailboxName);
FolderId fid1 = new FolderId(WellKnownFolderName.Inbox, mb);
var rootFolder = Folder.Bind(service, fid1);
var items = rootFolder.FindItems(view);
service.LoadPropertiesForItems(items, new PropertySet { ItemSchema.Attachments, ItemSchema.HasAttachments });
var matches = service.FindItems(fid1, searchFilters, view);
AddItems(service, matches, result, fullyQualifiedMailboxName, "InBox");
}
catch (ServiceResponseException)
{
//Ignore this indicates the user has no access to the mail box.
Debug.WriteLine(String.Format("Trouble accessing mailbox {0} assuming no access.", mailBoxName));
}
}
return result;
}
示例4: GetAllEmails
public static List<EmailMessage> GetAllEmails(ExchangeService service)
{
int offset = 0;
int pageSize = 50;
bool more = true;
ItemView view = new ItemView(pageSize, offset, OffsetBasePoint.Beginning);
view.PropertySet = PropertySet.IdOnly;
FindItemsResults<Item> findResults;
List<EmailMessage> emails = new List<EmailMessage>();
while (more)
{
findResults = service.FindItems(WellKnownFolderName.Inbox, view);
foreach (var item in findResults.Items)
{
emails.Add((EmailMessage)item);
}
more = findResults.MoreAvailable;
if (more)
{
view.Offset += pageSize;
}
}
PropertySet properties = (BasePropertySet.FirstClassProperties); //A PropertySet with the explicit properties you want goes here
service.LoadPropertiesForItems(emails, properties);
return emails;
}
示例5: GetAllEvents
public static List<CalendarEvent> GetAllEvents(String exchangeurl, String user, String pass)
{
List<CalendarEvent> events = new List<CalendarEvent>();
ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack;
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
service.Credentials = new WebCredentials(user, pass);
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.TraceListener = new TraceListener();
//When attempting to connect to EWS, it is much quicker to just use the url directly
//rather than using the auto-resolve. So we will first attempt the url, if that works
//then we are golden otherwise we will go for the auto-resolve.
CalendarFolder calendar = null;
if (exchangeurl != "")
{
service.Url = new Uri(exchangeurl);
try
{
// Try to initialize the calendar folder object with only the folder ID.
calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());
}
catch (Exception exp)
{
service.TraceListener.Trace("ExchangeUrlBindFail", exp.Message);
}
}
//calendar will still be null if we still have not bound correctly
if (calendar == null)
{
service.AutodiscoverUrl(user, RedirectionUrlValidationCallback);
// Try to initialize the calendar folder object with only the folder ID.
calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());
}
CalendarEvent cEvent = null;
// Initialize values for the start and end times, and the number of appointments to retrieve.
const int NUM_APPTS = 1000;
// Set the start and end time and number of appointments to retrieve.
CalendarView cView = new CalendarView(CalendarGlobals.StartDate, CalendarGlobals.EndDate, NUM_APPTS);
// Limit the properties returned to the appointment's subject, start time, and end time. (Body cannot be loaded with FindAppointments, we need to do that later)
cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End, AppointmentSchema.IsRecurring, AppointmentSchema.Id, AppointmentSchema.Location);
cView.PropertySet.RequestedBodyType = BodyType.Text;
// Retrieve a collection of appointments by using the calendar view.
FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);
Console.WriteLine("\nThe first " + NUM_APPTS + " appointments on your calendar from " + CalendarGlobals.StartDate.Date.ToShortDateString() +
" to " + CalendarGlobals.EndDate.Date.ToShortDateString() + " are: \n");
//Now that we have found the appointments that we want, we will be able to load the body
cView.PropertySet.Add(AppointmentSchema.Body);
service.LoadPropertiesForItems(appointments, cView.PropertySet);
foreach (Appointment a in appointments)
{
cEvent = new CalendarEvent(a.Id.ToString(), a.Start, a.End, a.Location, a.Subject, a.Body);
events.Add(cEvent);
}
return events;
}
示例6: GetAppointmentByUniqueId
/// <summary>
/// Get outlook item by unique Id
/// </summary>
/// <param name="service"></param>
/// <param name="uniqueId"></param>
/// <returns></returns>
public Appointment GetAppointmentByUniqueId(ref ExchangeService service, string uniqueId)
{
var appt = Appointment.Bind(service, uniqueId);
if ((appt != null))
{
//create property set and load necessary properties
var propertySet = new PropertySet(AppointmentSchema.Start,
AppointmentSchema.End,
AppointmentSchema.Location,
AppointmentSchema.IsAllDayEvent,
ItemSchema.Subject,
ItemSchema.Body);
//load properties
service.LoadPropertiesForItems(new List<Item> { appt }, propertySet);
return appt;
}
return null;
}
示例7: GetMailItemByUniqueId
/// <summary>
/// Get mail item by unique Id
/// </summary>
/// <param name="service"></param>
/// <param name="uniqueId"></param>
/// <returns></returns>
public object GetMailItemByUniqueId(ref ExchangeService service, string uniqueId)
{
var message = EmailMessage.Bind(service, uniqueId);
if ((message != null))
{
//create property set and load necessary properties
var propertySet = new PropertySet(EmailMessageSchema.ToRecipients, EmailMessageSchema.Sender,
ItemSchema.Subject,
ItemSchema.Body, ItemSchema.DateTimeReceived, ItemSchema.DateTimeSent, ItemSchema.HasAttachments,
ItemSchema.Attachments) { RequestedBodyType = BodyType.HTML };
//load properties
service.LoadPropertiesForItems(new List<Item> { message }, propertySet);
return message;
}
return null;
}
示例8: GetMailItemByExtendedProperty
/// <summary>
/// This function gets the mail item by the extended property
/// </summary>
/// <param name="service"></param>
/// <param name="folderId"></param>
/// <param name="msgFolderRootId"></param>
/// <param name="outlookMsgId"></param>
/// <param name="isIn"></param>
/// <returns></returns>
public object GetMailItemByExtendedProperty(ref ExchangeService service, FolderId folderId,
FolderId msgFolderRootId, string outlookMsgId, bool isIn)
{
EmailMessage message = null;
//Folder view
var viewFolders = new FolderView(int.MaxValue)
{
Traversal = FolderTraversal.Deep,
PropertySet = new PropertySet(BasePropertySet.IdOnly)
};
//email view
var viewEmails = new ItemView(int.MaxValue) { PropertySet = new PropertySet(BasePropertySet.IdOnly) };
//email filter
SearchFilter emailFilter =
new SearchFilter.IsEqualTo(
isIn
? MailboxExtendedPropertyDefinitionInbox
: MailboxExtendedPropertyDefinitionSent, outlookMsgId);
//search item in default folder
var findResults = service.FindItems(msgFolderRootId, emailFilter, viewEmails);
//check
if ((findResults != null) && findResults.TotalCount > 0 && findResults.FirstOrDefault() is EmailMessage)
{
//we found the email in default folder
message = (EmailMessage)findResults.First();
}
else
{
//find in all folders
var allFolders = service.FindFolders(msgFolderRootId, viewFolders);
foreach (var folder in allFolders.Folders)
{
//search
findResults = service.FindItems(folder.Id, emailFilter, viewEmails);
//check
if ((findResults != null) && findResults.TotalCount > 0 &&
findResults.FirstOrDefault() is EmailMessage)
{
//we found the email in somewhere
message = (EmailMessage)findResults.First();
break;
}
}
}
if (message != null)
{
//create property set and load necessary properties
var propertySet = new PropertySet(EmailMessageSchema.ToRecipients, EmailMessageSchema.Sender,
ItemSchema.Subject, ItemSchema.Body,
ItemSchema.DateTimeReceived, ItemSchema.DateTimeSent, ItemSchema.HasAttachments,
ItemSchema.Attachments) { RequestedBodyType = BodyType.HTML };
//load properties
service.LoadPropertiesForItems(findResults, propertySet);
}
return message;
}
示例9: Get
public IEnumerable<ApiCalendarModels> Get()
{
try
{
// Initialize values for the start and end times, and the number of appointments to retrieve.
DateTime startDate = DateTime.Now;
DateTime endDate = startDate.AddDays(30);
const int NUM_APPTS = 1000;
// Initialize the calendar folder object with only the folder ID.
ExchangeService service = new ExchangeService();
#region Authentication
// Set specific credentials.
service.Credentials = new NetworkCredential("[email protected]", "HuyHung0912");
#endregion
#region Endpoint management
// Look up the user's EWS endpoint by using Autodiscover.
service.AutodiscoverUrl("[email protected]", RedirectionCallback);
Console.WriteLine("EWS Endpoint: {0}", service.Url);
#endregion
CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());
// Set the start and end time and number of appointments to retrieve.
CalendarView cView = new CalendarView(startDate, endDate, NUM_APPTS);
// Limit the properties returned to the appointment's subject, start time, and end time.
cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End);
// Retrieve a collection of appointments by using the calendar view.
FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);
var res = service.LoadPropertiesForItems(
from Microsoft.Exchange.WebServices.Data.Item item in appointments select item,
PropertySet.FirstClassProperties);
var result = res.ToList();
List<ApiCalendarModels> data = new List<ApiCalendarModels>();
foreach (var item in result)
{
var itemResponse = (GetItemResponse)item;
var appt = (Appointment)itemResponse.Item;
var model = new ApiCalendarModels()
{
Id = itemResponse.Item.Id.UniqueId,
Subject = itemResponse.Item.Subject,
Date = appt.Start,
End = appt.End,
Body = itemResponse.Item.Body == null ? string.Empty : itemResponse.Item.Body.Text,
Attendee = itemResponse.Item.DisplayTo == null ? string.Empty : itemResponse.Item.DisplayTo
};
data.Add(model);
}
return data;
}
catch (Exception ex)
{
string s = ex.Message;
}
return null;
}