本文整理汇总了C#中ExchangeService.FindItems方法的典型用法代码示例。如果您正苦于以下问题:C# ExchangeService.FindItems方法的具体用法?C# ExchangeService.FindItems怎么用?C# ExchangeService.FindItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExchangeService
的用法示例。
在下文中一共展示了ExchangeService.FindItems方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindIncompleteTask
static IEnumerable<Microsoft.Exchange.WebServices.Data.Task> FindIncompleteTask(ExchangeService service)
{
// Specify the folder to search, and limit the properties returned in the result.
TasksFolder tasksfolder = TasksFolder.Bind(service,
WellKnownFolderName.Tasks,
new PropertySet(BasePropertySet.IdOnly, FolderSchema.TotalCount));
// Set the number of items to the smaller of the number of items in the Contacts folder or 1000.
int numItems = tasksfolder.TotalCount < 1000 ? tasksfolder.TotalCount : 1000;
// Instantiate the item view with the number of items to retrieve from the contacts folder.
ItemView view = new ItemView(numItems);
// To keep the request smaller, send only the display name.
view.PropertySet = new PropertySet(BasePropertySet.IdOnly, TaskSchema.Subject, TaskSchema.Status, TaskSchema.StartDate);
var filter = new SearchFilter.IsGreaterThan(TaskSchema.DateTimeCreated, DateTime.Now.AddYears(-10));
// Retrieve the items in the Tasks folder with the properties you selected.
FindItemsResults<Microsoft.Exchange.WebServices.Data.Item> taskItems = service.FindItems(WellKnownFolderName.Tasks, filter, view);
// If the subject of the task matches only one item, return that task item.
var results = new List<Microsoft.Exchange.WebServices.Data.Task>();
foreach (var task in taskItems)
{
var result = new Microsoft.Exchange.WebServices.Data.Task(service);
result = task as Microsoft.Exchange.WebServices.Data.Task;
results.Add(result);
}
return results;
}
示例2: Main
static void Main(string[] args)
{
var service = new ExchangeService();
service.Credentials = new NetworkCredential("your mail address", "your password");
try
{
service.Url = new Uri("http://exchange01/ews/exchange.asmx");
}
catch (AutodiscoverRemoteException ex)
{
Console.WriteLine(ex.Message);
}
FolderId inboxId = new FolderId(WellKnownFolderName.Inbox, "<<e-mail address>>");
var findResults = service.FindItems(inboxId, new ItemView(10));
foreach (var message in findResults.Items)
{
var msg = EmailMessage.Bind(service, message.Id, new PropertySet(BasePropertySet.IdOnly, ItemSchema.Attachments));
foreach (Attachment attachment in msg.Attachments)
{
if (attachment is FileAttachment)
{
FileAttachment fileAttachment = attachment as FileAttachment;
// Load the file attachment into memory and print out its file name.
fileAttachment.Load();
var filename = fileAttachment.Name;
bool b;
b = filename.Contains(".csv");
if (b == true)
{
bool a;
a = filename.Contains("meteo");
if (a == true)
{
var theStream = new FileStream("C:\\data\\attachments\\" + fileAttachment.Name, FileMode.OpenOrCreate, FileAccess.ReadWrite);
fileAttachment.Load(theStream);
theStream.Close();
theStream.Dispose();
}
}
}
else // Attachment is an item attachment.
{
// Load attachment into memory and write out the subject.
ItemAttachment itemAttachment = attachment as ItemAttachment;
itemAttachment.Load();
}
}
}
}
示例3: actualizarRevisionDirectivaE
public string actualizarRevisionDirectivaE(string asunto, string fechaInicio, string fechaLimite, string cuerpoTarea, string ubicacion)
{
string error = "";
try
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
service.UseDefaultCredentials = true;
service.Credentials = new WebCredentials("xxxxxxxxxxxx", "xxxxx", "xxxx");//@uanl.mx
service.AutodiscoverUrl("xxxxxxxxxxxxxxxxx");
string querystring = "Subject:'"+asunto +"'";
ItemView view = new ItemView(1);
FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Calendar, querystring, view);// <<--- Esta parte no la se pasar a VB
if (results.TotalCount > 0)
{
if (results.Items[0] is Appointment) //if is an appointment, could be other different than appointment
{
Appointment appointment = results.Items[0] as Appointment; //<<--- Esta parte no la se pasar a VB
if (appointment.MeetingRequestWasSent)//if was send I will update the meeting
{
appointment.Start = Convert.ToDateTime(fechaInicio);
appointment.End = Convert.ToDateTime(fechaLimite);
appointment.Body = cuerpoTarea;
appointment.Location = ubicacion;
appointment.Update(ConflictResolutionMode.AutoResolve);
}
else//if not, i will modify and sent it
{
appointment.Start = Convert.ToDateTime(fechaInicio);
appointment.End = Convert.ToDateTime(fechaLimite);
appointment.Body = cuerpoTarea;
appointment.Location = ubicacion;
appointment.Save(SendInvitationsMode.SendOnlyToAll);
}
}
}
else
{
error = "Wasn't found it's appointment";
return error;
}
return error;
}
catch
{
return error = "an error happend";
}
}
示例4: Main
static void Main(string[] args)
{
ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack;
var service = new ExchangeService(ExchangeVersion.Exchange2010_SP2)
{
Credentials = new WebCredentials("solar_hydro_one", "Summer270"),
//TraceEnabled = true,
//TraceFlags = TraceFlags.All
};
service.AutodiscoverUrl("[email protected]", RedirectionUrlValidationCallback);
var rootfolder = Folder.Bind(service, WellKnownFolderName.MsgFolderRoot);
rootfolder.Load();
var fid =
rootfolder.FindFolders(new FolderView(3))
.Where(folder => folder.DisplayName == "Backup")
.Select(folder => folder.Id).SingleOrDefault();
var dbContext = new HydroOneMeterDataContext();
var emailItems = service.FindItems(WellKnownFolderName.Inbox, new ItemView(10));
foreach (var eItem in emailItems)
{
if (eItem.Subject.Contains("Hydro One Meter Data") && eItem.HasAttachments && eItem is EmailMessage)
{
foreach (var fileAttachment in (EmailMessage.Bind(service, eItem.Id, new PropertySet(BasePropertySet.IdOnly, ItemSchema.Attachments))).Attachments.OfType<FileAttachment>().Select(attachment => attachment as FileAttachment))
{
fileAttachment.Load();
Console.WriteLine("Attachment name: " + fileAttachment.Name);
var hydroOneData = ProcessData(fileAttachment.Content);
if (hydroOneData.Any())
{
Console.WriteLine("Inserting " + hydroOneData.Count + " rows");
dbContext.HydroOneMeters.InsertAllOnSubmit(hydroOneData);
}
}
}
eItem.Move(fid);
}
dbContext.SubmitChanges();
Console.WriteLine("Done ... press any key to exit");
//Console.ReadKey();
}
示例5: accessShared
public void accessShared()
{
ServicePointManager.ServerCertificateValidationCallback = m_UrlBack.CertificateValidationCallBack;
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
// Get the information of the account.
service.Credentials = new WebCredentials(EMAIL_ACCOUNT, EMAIL_PWD);
// Set the url of server.
if (!AutodiscoverUrl(service, EMAIL_ACCOUNT))
{
return;
}
var mb = new Mailbox(SHARED_MAILBOX);
var fid1 = new FolderId(WellKnownFolderName.Inbox, mb);
// Add a search filter that searches on the body or subject.
List<SearchFilter> searchFilterCollection = new List<SearchFilter>();
searchFilterCollection.Add(new SearchFilter.ContainsSubstring(ItemSchema.Subject, SUBJECT_KEY_WORD));
SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, searchFilterCollection.ToArray());
// Create a view with a page size of 10.
var view = new ItemView(10);
// Identify the Subject and DateTimeReceived properties to return.
// Indicate that the base property will be the item identifier
view.PropertySet = new PropertySet(BasePropertySet.IdOnly, ItemSchema.Subject, ItemSchema.DateTimeReceived);
// Order the search results by the DateTimeReceived in descending order.
view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Ascending);
// Set the traversal to shallow. (Shallow is the default option; other options are Associated and SoftDeleted.)
view.Traversal = ItemTraversal.Shallow;
String[] invalidStings = { "\\", ",", ":", "*", "?", "\"", "<", ">", "|" };
PropertySet itemPorpertySet = new PropertySet(BasePropertySet.FirstClassProperties,
EmailMessageSchema.MimeContent);
FindItemsResults<Item> findResults = service.FindItems(fid1, searchFilter, view);
foreach (Item item in findResults.Items)
{
EmailMessage email = EmailMessage.Bind(service, item.Id, new PropertySet(BasePropertySet.IdOnly, ItemSchema.Attachments));
email.Load(itemPorpertySet);
string emailBody = email.Body.ToString();
}
}
示例6: RetrieveMailItems
/// <summary>
/// This function retuns the mail items for the given folder and for the date
/// </summary>
/// <param name="service"></param>
/// <param name="folderId"></param>
/// <param name="lastSyncDate"></param>
/// <returns></returns>
public FindItemsResults<Item> RetrieveMailItems(ref ExchangeService service, FolderId folderId,
DateTime lastSyncDate)
{
//email view
var emailView = new ItemView(int.MaxValue) { PropertySet = BasePropertySet.IdOnly };
//search filter collection
var searchFilterCollection =
new SearchFilter.SearchFilterCollection(LogicalOperator.And)
{
new SearchFilter.IsGreaterThanOrEqualTo(ItemSchema.DateTimeReceived, lastSyncDate)
};
//retrieve
var items = service.FindItems(folderId, searchFilterCollection, emailView);
return items;
}
示例7: ActualizarRevisionDirectivaCorreosE
public string ActualizarRevisionDirectivaCorreosE(string asunto, List<string> invitados )
{
string error = "";
try
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
service.UseDefaultCredentials = true;
service.Credentials = new WebCredentials("xxxxxxxxxxxxx", "xxxx", "xxxx");
service.AutodiscoverUrl("xxxxxxxxxxxxxxxxxxxx");
string querystring = "Subject:'" + asunto + "'";
ItemView view = new ItemView(1);
FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Calendar, querystring, view);// <<--- Esta parte no la se pasar a VB
if (results.TotalCount > 0)
{
if (results.Items[0] is Appointment) //if is an appointment, could be other different than appointment
{
Appointment appointment = results.Items[0] as Appointment; //<<--- Esta parte no la se pasar a VB
if (appointment.MeetingRequestWasSent)//if was send I will update the meeting
{
foreach (string invitado in invitados){
appointment.RequiredAttendees.Add(invitado);
}
appointment.Update(ConflictResolutionMode.AutoResolve);
}
else//if not, i will modify and sent it
{
appointment.Save(SendInvitationsMode.SendOnlyToAll);
}
}
}
else
{
error = "Wasn't found it's appointment";
return error;
}
return error;
}
catch (Exception ex)
{
return error = ex.Message;
}
}
示例8: GetContacts
public IEnumerable<Kontakt> GetContacts(string userName, string password)
{
// Exchange Online is running 2010 sp1
var service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
// passing the credentials to the service instance
service.Credentials = new WebCredentials(userName, password);
// AutoDiscover is done by redirection to general AutoDiscover Service, so we have to allow this
service.AutodiscoverUrl(userName, delegate { return true; });
// Exchange is using an search based API, so let's look for contacts in the user's contact folder...
var items = service.FindItems(WellKnownFolderName.Contacts, new ItemView(100));
return items.Cast<Contact>().Select(contact => new Kontakt
{
Vorname = contact.GivenName,
Nachname = contact.Surname,
Email = contact.EmailAddresses[EmailAddressKey.EmailAddress1].Address
});
}
示例9: Main
static void Main(string[] args)
{
var service = new ExchangeService(ExchangeVersion.Exchange2010);
// Setting credentials is unnecessary when you connect from a computer that is logged on to the domain.
service.Credentials = new WebCredentials(Settings.Default.username, Settings.Default.password, Settings.Default.domain);
// Or use NetworkCredential directly (WebCredentials is a wrapper around NetworkCredential).
//To set the URL manually, use the following:
//service.Url = new Uri("https://proliant32.hci.tetra.ppf.cz/EWS/Exchange.asmx");
//To set the URL by using Autodiscover, use the following:
service.AutodiscoverUrl("[email protected]");
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(10));
foreach (Item item in findResults.Items)
{
Console.WriteLine(item.Subject);
}
}
示例10: GetExchange2007Email
/// <summary>
/// Gets e-mail using Exchange 2007.
/// </summary>
/// <returns></returns>
public static List<OEmailLog> GetExchange2007Email()
{
ServicePointManager.ServerCertificateValidationCallback = TrustAllCertificates;
OApplicationSetting appSetting = OApplicationSetting.Current;
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new NetworkCredential(appSetting.EmailUserName, Security.Decrypt(appSetting.EmailPassword), appSetting.EmailDomain);
service.Url = new Uri(appSetting.EmailExchangeWebServiceUrl);
FindItemsResults<Item> findResults =
service.FindItems(WellKnownFolderName.Inbox, new ItemView(100));
List<OEmailLog> emailList = new List<OEmailLog>();
foreach (Item item in findResults.Items)
{
EmailMessage emailMessage = item as EmailMessage;
if (emailMessage != null)
{
emailMessage.Load();
OEmailLog emailLog1 = OEmailLog.WriteToEmailLog(emailMessage.From.Address, emailMessage.Subject, emailMessage.Body);
//Connection.ExecuteQuery("#database", "INSERT INTO EmailLog (DateTimeReceived, FromRecipient, Subject, EmailBody, ObjectID, IsDeleted, CreatedDateTime, ModifiedDateTime, CreatedUser, ModifiedUser) VALUES ('" + DateTime.Now.ToString() + "', '" + emailMessage.From.Address +
// "', '" + emailMessage.Subject + "', '" + emailMessage.Body + "', newid(), 0, getdate(), getdate(), '*** SYSTEM ***', '*** SYSTEM ***')");
//OEmailLog emailLog = TablesLogic.tEmailLog.Load(TablesLogic.tEmailLog.FromRecipient == emailMessage.From.Address & TablesLogic.tEmailLog.Subject == emailMessage.Subject);
OEmailLog emailLog = TablesLogic.tEmailLog.Load(emailLog1.ObjectID);
if (emailLog != null)
{
emailList.Add(emailLog1);
emailMessage.Delete(DeleteMode.MoveToDeletedItems);
}
else
{
string message = emailMessage.From.Address + "<br/>" + emailMessage.Subject + "<br/>" + emailMessage.Body;
OMessage.SendMail(appSetting.EmailForAMOSFailure, appSetting.MessageEmailSender, "Received Email Log (CAMPS CCL) Failure on " + DateTime.Now.ToString(), message, true);
}
}
}
return emailList;
}
示例11: ConnectToExchange
public void ConnectToExchange()
{
ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);
ExchangeService es = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
es.UseDefaultCredentials = true;
es.Credentials = new WebCredentials("[email protected]", "bulova1");
es.Url = new Uri("https://mymail.amfam.net/");
// Query the unread messages
try
{
ItemView view = new ItemView(20);
FindItemsResults<Item> findResults = es.FindItems(WellKnownFolderName.Inbox, view);
foreach (EmailMessage m in findResults)
{
if (m.HasAttachments)
{
foreach (Attachment atmt in m.Attachments)
{
this.Eatmt = atmt;
}
// TODO :: Load file name into a database and Load file attachments into a directory
updateEAppsTable(m.From.ToString(), m.Subject.ToString(), (DateTime)m.DateTimeReceived, (DateTime)m.DateTimeSent, this.Eatmt);
}
else
{
// TODO :: POST to database.
updateEAppsTable(m.From.ToString(), m.Subject.ToString(), (DateTime)m.DateTimeReceived, (DateTime)m.DateTimeSent);
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
示例12: GetItems
private List<Item> GetItems(ExchangeService service, SearchFilter filter, WellKnownFolderName folder, PropertySet propertySet)
{
if (service == null)
{
return null;
}
List<Item> items = new List<Item>();
if (propertySet == null)
{
propertySet = new PropertySet(BasePropertySet.IdOnly);
}
const Int32 pageSize = 50;
ItemView itemView = new ItemView(pageSize);
itemView.PropertySet = propertySet;
FindItemsResults<Item> searchResults = null;
try
{
do
{
searchResults = service.FindItems(folder,
filter, itemView);
items.AddRange(searchResults.Items);
itemView.Offset += pageSize;
} while (searchResults.MoreAvailable);
}
catch (Exception ex)
{
if (!CheckServerConnection(domain))
{
NotifyDownloadStatus(DownloadStatus.INFORM, "Unable to connect to Exchange server. Please check.");
}
else
{
NotifyDownloadStatus(DownloadStatus.INFORM, "The username or password is incorrect. Please try again.");
}
return null;
}
return items;
}
示例13: GetItems
private List<Item> GetItems(ExchangeService service, SearchFilter filter, WellKnownFolderName folder, PropertySet propertySet)
{
if (service == null)
{
return null;
}
List<Item> items = new List<Item>();
if (propertySet == null)
{
propertySet = new PropertySet(BasePropertySet.IdOnly);
}
const Int32 pageSize = 50;
ItemView itemView = new ItemView(pageSize);
itemView.PropertySet = propertySet;
FindItemsResults<Item> searchResults = null;
try
{
do
{
searchResults = service.FindItems(folder,
filter, itemView);
items.AddRange(searchResults.Items);
itemView.Offset += pageSize;
} while (searchResults.MoreAvailable);
}
catch (Exception ex)
{
NotifyDownloadStatus(DownloadStatus.INFORM, ex.Message);
return null;
}
return items;
}
示例14: OnStartAfter
private void OnStartAfter()
{
string sMailBox = System.String.Empty;
string sMailServerUrl = System.String.Empty;
string sUser = System.String.Empty;
string sPassword = System.String.Empty;
string sDomain = System.String.Empty;
string sFolderRoot = System.String.Empty;
int iItemsProccesing = 0;
int iScanDelay = 0;
Boolean bFolderDestDomain = false;
Boolean bDestinationFileFormatLong = false;
Boolean bProcessingFileToLog = false;
if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource, sLog);
sEvent = "Service started";
EventLog.WriteEntry(sSource, sEvent);
try
{
sMailBox = ConfigurationManager.AppSettings["MailBox"];
sMailServerUrl = ConfigurationManager.AppSettings["MailServerUrl"];
sUser = ConfigurationManager.AppSettings["User"];
sPassword = ConfigurationManager.AppSettings["Password"];
sDomain = ConfigurationManager.AppSettings["Domain"];
sFolderRoot = ConfigurationManager.AppSettings["FolderRoot"];
iItemsProccesing = Convert.ToInt32(ConfigurationManager.AppSettings["ItemsProccesing"]); // How much emails retrieve to view
iScanDelay = Convert.ToInt32(ConfigurationManager.AppSettings["ScanDelay"]); // Delay between scan Inbox
bFolderDestDomain = Convert.ToBoolean(ConfigurationManager.AppSettings["FolderDestinationNameWithDomain"]);
bDestinationFileFormatLong = Convert.ToBoolean(ConfigurationManager.AppSettings["DestinationFileFormatLong"]); //
bProcessingFileToLog = Convert.ToBoolean(ConfigurationManager.AppSettings["ProcessingFileToLog"]); //
sEvent = "MailBox=" + sMailBox + "\n" +
"MailServerUrl=" + sMailServerUrl + "\n" +
"User=" + sUser + "\n" +
"Domain=" + sDomain + "\n" +
"FolderRoot=" + sFolderRoot + "\n" +
"ItemsProccesing=" + iItemsProccesing + "\n" +
"ScanDelay=" + iScanDelay + "\n" +
"FolderDestDomain=" + bFolderDestDomain + "\n" +
"DestinationFileFormatLong=" + bDestinationFileFormatLong + "\n" +
"ProcessingFileToLog=" + bProcessingFileToLog;
EventLog.WriteEntry(sSource, sEvent);
}
catch (Exception e)
{
EventLog.WriteEntry(sSource, e.Message, EventLogEntryType.Warning, 234);
}
////////////////////;
//
Boolean bItemDelete = false;
string sFilePath = System.String.Empty;
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
ServicePointManager.ServerCertificateValidationCallback = (obj, certificate, chain, errors) => true;
service.Credentials = new System.Net.NetworkCredential(sUser, sPassword, sDomain);
Uri uriMailServerUrl = new Uri(sMailServerUrl);
service.Url = uriMailServerUrl;
FolderId InboxId = new FolderId(WellKnownFolderName.Inbox, sMailBox);
FindItemsResults<Item> findResults = null;
while (true)
{
try
{
findResults = service.FindItems(InboxId, new ItemView(iItemsProccesing));
}
catch (Exception e)
{
sEvent = "Exchange Server:" +e.Source + ":" + e.Message;
EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Warning, 234);
}
if (findResults != null)
{
foreach (Item message in findResults.Items)
{
bItemDelete = true;
if (message.HasAttachments)
{
EmailMessage emailMessage = EmailMessage.Bind(service, message.Id, new PropertySet(BasePropertySet.IdOnly, ItemSchema.Attachments));
#if DEBUG
sEvent = "Debug event Subject: " + message.Subject + " Date: " + message.DateTimeReceived;
EventLog.WriteEntry(sSource, sEvent );
//.........这里部分代码省略.........
示例15: GetItems
private List<Item> GetItems(ExchangeService service, SearchFilter filter, WellKnownFolderName folder, PropertySet propertySet)
{
if (service == null)
{
return null;
}
List<Item> items = new List<Item>();
if (propertySet == null)
{
propertySet = new PropertySet(BasePropertySet.IdOnly);
}
const Int32 pageSize = 50;
ItemView itemView = new ItemView(pageSize);
itemView.PropertySet = propertySet;
FindItemsResults<Item> searchResults = null;
try
{
do
{
searchResults = service.FindItems(folder,
filter, itemView);
items.AddRange(searchResults.Items);
itemView.Offset += pageSize;
} while (searchResults.MoreAvailable);
}
catch (Exception ex)
{
if (!CheckServerConnection(domain))
{
NotifyDownloadStatus(DownloadStatus.INFORM, CMController.Properties.Resources.unconnect_exchange_server);
return null;
}
else
{
NotifyDownloadStatus(DownloadStatus.INFORM, CMController.Properties.Resources.wrong_username_password);
return null;
}
}
return items;
}