/// <summary> /// Saves this appointment in the specified folder. Calling this method results in at least one call to EWS. /// Mutliple calls to EWS might be made if attachments have been added. /// </summary> /// <param name="destinationFolderName">The name of the folder in which to save this appointment.</param> /// <param name="sendInvitationsMode">Specifies if and how invitations should be sent if this appointment is a meeting.</param> public void Save(WellKnownFolderName destinationFolderName, SendInvitationsMode sendInvitationsMode) { this.InternalCreate( new FolderId(destinationFolderName), null, sendInvitationsMode); }
private static 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 = 10; ItemView itemView = new ItemView(pageSize); itemView.PropertySet = propertySet; FindItemsResults <Item> searchResults = null; do { searchResults = service.FindItems(folder, filter, itemView); items.AddRange(searchResults.Items); itemView.Offset += pageSize; } while (searchResults.MoreAvailable); return(items); }
/// <summary> /// Saves this appointment in the specified folder. Calling this method results in at least one call to EWS. /// Mutliple calls to EWS might be made if attachments have been added. /// </summary> /// <param name="destinationFolderName">The name of the folder in which to save this appointment.</param> /// <param name="sendInvitationsMode">Specifies if and how invitations should be sent if this appointment is a meeting.</param> public System.Threading.Tasks.Task Save(WellKnownFolderName destinationFolderName, SendInvitationsMode sendInvitationsMode) { return(this.InternalCreate( new FolderId(destinationFolderName), null, sendInvitationsMode)); }
//https://www.cnblogs.com/tuenbo/p/9870396.html public FolderId FindFolderIdByDisplayName(ExchangeService service, WellKnownFolderName SearchFolder) { // Specify the root folder to be searched. Folder rootFolder = Folder.Bind(service, SearchFolder); return(rootFolder.Id); }
/// <summary> /// Binds to an existing folder, whatever its actual type is, and loads its first class properties. /// Calling this method results in a call to EWS. /// </summary> /// <param name="service">The service to use to bind to the folder.</param> /// <param name="name">The name of the folder to bind to.</param> /// <returns>A Folder instance representing the folder with the specified name.</returns> public static Folder Bind(ExchangeService service, WellKnownFolderName name) { return(Folder.Bind( service, new FolderId(name), PropertySet.FirstClassProperties)); }
/// <summary> /// Method is returning Folder object from WellKnownFolderName enum. /// </summary> /// <param name="wellKnownFolderName">WellKnownFolderName for which Folder object needs to be returned.</param> /// <param name="ewsSession">ExchangeService session context.</param> /// <returns></returns> public static Folder GetWellKnownFolder(WellKnownFolderName wellKnownFolderName, ExchangeService ewsSession) { FolderId wellKnownFolderId = new FolderId(wellKnownFolderName); Folder wellKnownFolder = Folder.Bind(ewsSession, wellKnownFolderId); return wellKnownFolder; }
public IEnumerable <MailItem> GetMailFrom(WellKnownFolderName folderName, int maxItems) { var view = new ItemView(maxItems) { Traversal = ItemTraversal.Shallow, }; FindItemsResults <Item> findResults = service.FindItems(folderName, view); if (findResults.Count() > 0) { var itempropertyset = new PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.From, EmailMessageSchema.ToRecipients, ItemSchema.Attachments) { RequestedBodyType = BodyType.Text }; ServiceResponseCollection <GetItemResponse> items = service.BindToItems(findResults.Select(item => item.Id), itempropertyset); foreach (var item in items) { var emailMessage = item.Item as EmailMessage; var mailItem = MailItem.FromExchangeMailMessage(emailMessage); yield return(mailItem); } } }
protected OutlookEmailBaseOperator( ILocalSwitchboard switchboard, string emailAddress, string password, int maxDequeueCount, SearchFilter filter = null, WellKnownFolderName folder = WellKnownFolderName.Inbox, SortDirection sortDirection = SortDirection.Ascending) { this.emailAddress = emailAddress; this.password = password; this.recieveMessagesOnly = true; this.filter = filter; this.folder = folder; this.maxDequeueCount = maxDequeueCount; this.sortDirection = sortDirection; if (null != switchboard) { this.Switchboards.Add(switchboard); switchboard.Operator = this; } this.ID = 0; if (null == switchboard && this.recieveMessagesOnly) { throw new SwitchBoardNeededWhenRecievingMessagesException(); } }
private void FindRetentionStampedFolders() { string sPolicy = string.Empty; this.Cursor = Cursors.WaitCursor; if (txtTagId.Text.Trim().Length == 0) { MessageBox.Show("Retention Id must be enered before seraching folders.", "Entry Error"); } if (lvUserRetentionTags.SelectedItems.Count > 0) { ListViewItem o = lvUserRetentionTags.SelectedItems[0]; sPolicy = txtTagId.Text.Trim(); // o.SubItems[5].Text; WellKnownFolderName oParentFolder = this.wellKnownFolderCombo.SelectedItem.Value; DisplayFindRetentionStampedFoldersInListView( _ExchangeService, oParentFolder, sPolicy, ref this.oLvRetionStampedFolders); } this.Cursor = Cursors.Default; }
/// <summary> /// Use this to get notified of events, this uses StreamingNotifications /// </summary> /// <param name="wellKnownFolderName">WellKnownFolderName to look to, Inbox if none is specified</param> /// <param name="eventTypes">params EventType, if nothing specified than EventType.NewMail is taken</param> /// <returns>IObservable which publishes NotificationEvent</returns> public IObservable <NotificationEvent> Observe(WellKnownFolderName wellKnownFolderName = WellKnownFolderName.Inbox, params EventType[] eventTypes) { if (eventTypes == null || eventTypes.Length == 0) { eventTypes = new[] { EventType.NewMail }; } return(Observable.Create <NotificationEvent>( observer => { try { var streamingSubscription = Service.SubscribeToStreamingNotifications(new FolderId[] { wellKnownFolderName }, eventTypes); var connection = new StreamingSubscriptionConnection(Service, 1); connection.AddSubscription(streamingSubscription); connection.OnNotificationEvent += (sender, notificationEventArgs) => { foreach (var notificationEvent in notificationEventArgs.Events) { observer.OnNext(notificationEvent); } }; // Handle errors connection.OnSubscriptionError += (sender, subscriptionErrorEventArgs) => observer.OnError(subscriptionErrorEventArgs.Exception); // Use this to bool disposedConnection = false; // As the time to live is maximum 30 minutes, the connection is closed by the server connection.OnDisconnect += (sender, subscriptionErrorEventArgs) => { if (subscriptionErrorEventArgs.Exception != null || disposedConnection) { return; } // Connection closed by server, just reconnect // See: https://msdn.microsoft.com/en-us/library/office/hh312849.aspx // "This behavior is expected and is not an error condition" connection.Open(); }; // Start the connection connection.Open(); // Return a disposable which disposed the connection and unsubscribes the subscription return Disposable.Create(() => { disposedConnection = true; connection.Dispose(); streamingSubscription.Unsubscribe(); }); } catch (Win32Exception e) { observer.OnError(e); return Disposable.Empty; } })); }
//private FolderTraversal GetSearchDepth(string sSearchDepth) //{ // FolderTraversal oFolderTraversal = FolderTraversal.Shallow; // switch (sSearchDepth) // { // case "Shallow": // oFolderTraversal = FolderTraversal.Shallow; // Shallow, Deep, SoftDeleted // break; // case "Deep": // oFolderTraversal = FolderTraversal.Deep; // Shallow, Deep, SoftDeleted // break; // case "SoftDeleted": // oFolderTraversal = FolderTraversal.SoftDeleted; // Shallow, Deep, SoftDeleted // break; // } // return oFolderTraversal; //} private void DisplayFindRetentionStampedFoldersInListView( ExchangeService oExchangeService, WellKnownFolderName oParentFolder, string sPolicy, ref ListView oListView) { oListView.Clear(); oListView.View = View.Details; oListView.GridLines = true; oListView.Columns.Add("Id", 200, HorizontalAlignment.Left); oListView.Columns.Add("FolderName", 250, HorizontalAlignment.Left); oListView.Columns.Add("Folder Path", 400, HorizontalAlignment.Left); oListView.Columns.Add("PR_POLICY_TAG", 100, HorizontalAlignment.Left); oListView.Columns.Add("PR_RETENTION_FLAGS", 100, HorizontalAlignment.Left); oListView.Columns.Add("PR_RETENTION_Period", 100, HorizontalAlignment.Left); oListView.Columns.Add("PR_IS_HIDDEN", 100, HorizontalAlignment.Left); oListView.Columns.Add("TotalCount", 100, HorizontalAlignment.Left); //GetUserRetentionPolicyTagsResponse oResponse = null; // oResponse = _ExchangeService.GetUserRetentionPolicyTags(); //FolderTraversal oFolderTraversal = GetSearchDepth(cmboSearchDepth.Text); FolderTraversal oFolderTraversal = FolderTraversal.Deep; this.Cursor = Cursors.WaitCursor; FindFoldersWithPolicyTag(_ExchangeService, oParentFolder, sPolicy, ref oLvRetionStampedFolders, oFolderTraversal); this.Cursor = Cursors.Default; }
/// <summary> /// Binds to an existing calendar folder and loads its first class properties. /// Calling this method results in a call to EWS. /// </summary> /// <param name="service">The service to use to bind to the calendar folder.</param> /// <param name="name">The name of the calendar folder to bind to.</param> /// <returns>A CalendarFolder instance representing the calendar folder with the specified name.</returns> public static new Task <CalendarFolder> Bind(ExchangeService service, WellKnownFolderName name) { return(CalendarFolder.Bind( service, new FolderId(name), PropertySet.FirstClassProperties)); }
/// <summary> /// Saves this item in a specific folder. Calling this method results in at least one call to EWS. /// Mutliple calls to EWS might be made if attachments have been added. /// </summary> /// <param name="parentFolderName">The name of the folder in which to save this item.</param> public System.Threading.Tasks.Task Save(WellKnownFolderName parentFolderName) { return(this.InternalCreate( new FolderId(parentFolderName), MessageDisposition.SaveOnly, null)); }
/// <summary> /// Saves this item in a specific folder. Calling this method results in at least one call to EWS. /// Mutliple calls to EWS might be made if attachments have been added. /// </summary> /// <param name="parentFolderName">The name of the folder in which to save this item.</param> public void Save(WellKnownFolderName parentFolderName) { this.InternalCreate( new FolderId(parentFolderName), MessageDisposition.SaveOnly, null); }
/// <summary> /// Saves this appointment in the specified folder. Calling this method results in at least one call to EWS. /// Mutliple calls to EWS might be made if attachments have been added. /// </summary> /// <param name="destinationFolderName">The name of the folder in which to save this appointment.</param> /// <param name="sendInvitationsMode">Specifies if and how invitations should be sent if this appointment is a meeting.</param> public System.Threading.Tasks.Task Save(WellKnownFolderName destinationFolderName, SendInvitationsMode sendInvitationsMode, CancellationToken token = default(CancellationToken)) { return(this.InternalCreate( new FolderId(destinationFolderName), null, sendInvitationsMode, token)); }
/// <summary> /// Saves this item in a specific folder. Calling this method results in at least one call to EWS. /// Mutliple calls to EWS might be made if attachments have been added. /// </summary> /// <param name="parentFolderName">The name of the folder in which to save this item.</param> public System.Threading.Tasks.Task Save(WellKnownFolderName parentFolderName, CancellationToken token = default(CancellationToken)) { return(this.InternalCreate( new FolderId(parentFolderName), MessageDisposition.SaveOnly, null, token)); }
/// <summary> /// Binds to an existing tasks folder and loads its first class properties. /// Calling this method results in a call to EWS. /// </summary> /// <param name="service">The service to use to bind to the tasks folder.</param> /// <param name="name">The name of the tasks folder to bind to.</param> /// <returns>A TasksFolder instance representing the tasks folder with the specified name.</returns> public static new Task <TasksFolder> Bind(ExchangeService service, WellKnownFolderName name, CancellationToken token = default(CancellationToken)) { return(TasksFolder.Bind( service, new FolderId(name), PropertySet.FirstClassProperties, token)); }
/// <summary> /// Binds to an existing folder, whatever its actual type is, and loads the specified set of properties. /// Calling this method results in a call to EWS. /// </summary> /// <param name="service">The service to use to bind to the folder.</param> /// <param name="name">The name of the folder to bind to.</param> /// <param name="propertySet">The set of properties to load.</param> /// <returns>A Folder instance representing the folder with the specified name.</returns> public static Folder Bind( ExchangeService service, WellKnownFolderName name, PropertySet propertySet) { return(Folder.Bind( service, new FolderId(name), propertySet)); }
/// <summary> /// Binds to an existing calendar folder and loads the specified set of properties. /// Calling this method results in a call to EWS. /// </summary> /// <param name="service">The service to use to bind to the calendar folder.</param> /// <param name="name">The name of the calendar folder to bind to.</param> /// <param name="propertySet">The set of properties to load.</param> /// <returns>A CalendarFolder instance representing the calendar folder with the specified name.</returns> public static new CalendarFolder Bind( ExchangeService service, WellKnownFolderName name, PropertySet propertySet) { return CalendarFolder.Bind( service, new FolderId(name), propertySet); }
/// <summary> /// Initializes a new instance of the <see cref="ExchangeServiceSubscription" /> class. /// </summary> /// <param name="service">The <see cref="ExchangeService" />.</param> /// <param name="folder">The folder to monitor.</param> internal ExchangeServiceSubscription(ExchangeService service, WellKnownFolderName folder) { _service = service; _subscriptionConnection = new StreamingSubscriptionConnection(_service, 30); // 30 minutes is the max StreamingSubscription subscription = _service.SubscribeToStreamingNotifications(new FolderId[] { folder }, EventType.NewMail); _subscriptionConnection.AddSubscription(subscription); _subscriptionConnection.OnNotificationEvent += (s, e) => SubscriptionNotification?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Binds to an existing calendar folder and loads the specified set of properties. /// Calling this method results in a call to EWS. /// </summary> /// <param name="service">The service to use to bind to the calendar folder.</param> /// <param name="name">The name of the calendar folder to bind to.</param> /// <param name="propertySet">The set of properties to load.</param> /// <returns>A CalendarFolder instance representing the calendar folder with the specified name.</returns> public static new Task <CalendarFolder> Bind( ExchangeService service, WellKnownFolderName name, PropertySet propertySet) { return(CalendarFolder.Bind( service, new FolderId(name), propertySet)); }
private static void SearchMail(ExchangeService service, WellKnownFolderName folder, string SearchString) { ItemView view = new ItemView(int.MaxValue); PropertySet itempropertyset = new PropertySet(BasePropertySet.FirstClassProperties); itempropertyset.RequestedBodyType = BodyType.Text; view.PropertySet = itempropertyset; FindItemsResults <Item> findResults = null; findResults = service.FindItems(folder, view); foreach (Item item in findResults.Items) { if (item.Subject.Contains(SearchString)) { Console.WriteLine("\r\n"); Console.WriteLine("[+]Match mail found,Subject match"); Console.WriteLine("[*]Folder:{0}", folder); Console.WriteLine("[*]Subject:{0}", item.Subject); Console.WriteLine("[*]Size:{0}", item.Size); Console.WriteLine("[*]ItemId:{0}", item.Id); } if (item.HasAttachments) { EmailMessage message = EmailMessage.Bind(service, item.Id, new PropertySet(ItemSchema.Attachments)); foreach (Attachment attachment in message.Attachments) { FileAttachment fileAttachment = attachment as FileAttachment; fileAttachment.Load(); if (fileAttachment.Name.Contains(SearchString)) { Console.WriteLine("\r\n"); Console.WriteLine("[+]Match mail found,Attachment match"); Console.WriteLine("[*]Folder:{0}", folder); Console.WriteLine("[*]Subject:{0}", item.Subject); Console.WriteLine(" - Attachments:{0}", fileAttachment.Name); Console.WriteLine("[*]Size:{0}", item.Size); Console.WriteLine("[*]ItemId:{0}", item.Id); } } } item.Load(itempropertyset); if (item.Body.Text != null) { if (item.Body.Text.Contains(SearchString)) { Console.WriteLine("\r\n"); Console.WriteLine("[+]Match mail found,MessageBody match"); Console.WriteLine("[*]Folder:{0}", folder); Console.WriteLine("[*]Subject:{0}", item.Subject); Console.WriteLine("[*]Size:{0}", item.Size); Console.WriteLine("[*]ItemId:{0}", item.Id); } } } }
/// <summary> /// Binds to an existing user configuration and loads the specified properties. /// Calling this method results in a call to EWS. /// </summary> /// <param name="service">The service to which the user configuration is bound.</param> /// <param name="name">The name of the user configuration.</param> /// <param name="parentFolderName">The name of the folder containing the user configuration.</param> /// <param name="properties">The properties to load.</param> /// <returns>A user configuration instance.</returns> static UserConfiguration Bind( ExchangeService service, String name, WellKnownFolderName parentFolderName, UserConfigurationProperties properties) { return(UserConfiguration.Bind( service, name, new FolderId(parentFolderName), properties)); }
public static void CreateItemUsingMime(ExchangeService oExchangeService, WellKnownFolderName oWellKnownFolderName, string sMIME, ref ItemId oItemId) { EmailMessage oMessage = new EmailMessage(oExchangeService); byte[] byteMIME = Encoding.ASCII.GetBytes(sMIME); oMessage.MimeContent = new MimeContent(); oMessage.MimeContent.Content = byteMIME; oMessage.Save(oWellKnownFolderName); oItemId = oMessage.Id; }
/// <summary> /// Binds to an existing contacts folder and loads the specified set of properties. /// </summary> /// <param name="service">The service to use to bind to the contacts folder.</param> /// <param name="name">The name of the contacts folder to bind to.</param> /// <param name="propertySet">The set of properties to load.</param> /// <returns>A ContactsFolder instance representing the contacts folder with the specified name.</returns> public static new Task <ContactsFolder> Bind( ExchangeService service, WellKnownFolderName name, PropertySet propertySet, CancellationToken token = default(CancellationToken)) { return(ContactsFolder.Bind( service, new FolderId(name), propertySet, token)); }
private static void ViewMail(ExchangeService service, WellKnownFolderName folder, string IdString) { ItemView view = new ItemView(int.MaxValue); PropertySet itempropertyset = new PropertySet(BasePropertySet.FirstClassProperties); itempropertyset.RequestedBodyType = BodyType.Text; view.PropertySet = itempropertyset; FindItemsResults <Item> findResults = null; findResults = service.FindItems(folder, view); foreach (Item item in findResults.Items) { if (item.Id.ToString() == IdString) { Console.WriteLine("\r\n"); Console.WriteLine("[+]Mail found"); Console.WriteLine("[*]Folder:{0}", folder); if (item.Subject != null) { Console.WriteLine("[*]Subject:{0}", item.Subject); } else { Console.WriteLine("[*]Subject:<null>"); } Console.WriteLine("[*]HasAttachments:{0}", item.HasAttachments); if (item.HasAttachments) { EmailMessage message = EmailMessage.Bind(service, item.Id, new PropertySet(ItemSchema.Attachments)); foreach (Attachment attachment in message.Attachments) { FileAttachment fileAttachment = attachment as FileAttachment; fileAttachment.Load(); Console.WriteLine(" - Attachments:{0}", fileAttachment.Name); } } Console.WriteLine("[*]ItemId:{0}", item.Id); Console.WriteLine("[*]DateTimeCreated:{0}", item.DateTimeCreated); Console.WriteLine("[*]DateTimeReceived:{0}", item.DateTimeReceived); Console.WriteLine("[*]DateTimeSent:{0}", item.DateTimeSent); Console.WriteLine("[*]DisplayCc:{0}", item.DisplayCc); Console.WriteLine("[*]DisplayTo:{0}", item.DisplayTo); Console.WriteLine("[*]InReplyTo:{0}", item.InReplyTo); Console.WriteLine("[*]Categories:{0}", item.Categories); Console.WriteLine("[*]Culture:{0}", item.Culture); Console.WriteLine("[*]IsFromMe:{0}", item.IsFromMe); Console.WriteLine("[*]ItemClass:{0}", item.ItemClass); Console.WriteLine("[*]Size:{0}", item.Size); item.Load(itempropertyset); Console.WriteLine("[*]MessageBody:{0}", item.Body); } } }
static void CreateFolder(ExchangeService service, string DisplayName, WellKnownFolderName DestinationFolder) { // Instantiate the Folder object. Folder folder = new Folder(service); // Specify the name of the new folder. folder.DisplayName = DisplayName; // Create the new folder in the specified destination folder. folder.Save(DestinationFolder); Console.WriteLine("Folder created:" + folder.DisplayName); }
/// <summary> /// Adds a well-known folder to the collection. /// </summary> /// <param name="folderName">The well known folder to add.</param> /// <returns>A FolderId encapsulating the specified Id.</returns> public FolderId Add(WellKnownFolderName folderName) { if (this.Contains(folderName)) { throw new ArgumentException(Strings.IdAlreadyInList, "folderName"); } FolderId folderId = new FolderId(folderName); this.InternalAdd(folderId); return(folderId); }
private static void DeleteFolder(ExchangeService service, WellKnownFolderName parentFolder, String folderName) { SearchFilter searchFilter = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, folderName); Folder folder = GetFolder(service, searchFilter, parentFolder); if (folder != null) { Console.WriteLine("Delete the folder '{0}'", folderName); folder.Delete(DeleteMode.HardDelete); Console.WriteLine(); } }
private static void CreateTask(ExchangeService service, string Subject, WellKnownFolderName DestinationFolder) { // Instaniate the Task object. Task task = new Task(service); // Specify the subject and body of the new task. task.Subject = Subject; task.Body = new MessageBody(BodyType.Text, "This is an example of a simple task created using EWS Managed API."); // Create the new task in the specified destination folder. task.Save(DestinationFolder); Console.WriteLine("Task created: " + task.Subject); }
private void CreateContactsFolder(ExchangeService svc, string folderName, WellKnownFolderName folderWellKnow) { ContactsFolder folder = new ContactsFolder(svc); folder.DisplayName = folderName; try { folder.Save(folderWellKnow); } catch (Exception erro) { ValidationCreationFolderException(erro); } }
public Folder GetDefaultFolder(WellKnownFolderName folderName, out Exception ex) { Folder result = null; ex = null; try { result = base.InvokeServiceCall <Folder>(() => Folder.Bind(this.Service, folderName)); } catch (DataSourceOperationException ex2) { ex = ex2; } return(result); }
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; }
/// <summary> /// Saves the user configuration. Calling this method results in a call to EWS. /// </summary> /// <param name="name">The name of the user configuration.</param> /// <param name="parentFolderName">The name of the folder in which to save the user configuration.</param> public void Save(string name, WellKnownFolderName parentFolderName) { this.Save(name, new FolderId(parentFolderName)); }
/// <summary> /// Binds to an existing user configuration and loads the specified properties. /// Calling this method results in a call to EWS. /// </summary> /// <param name="service">The service to which the user configuration is bound.</param> /// <param name="name">The name of the user configuration.</param> /// <param name="parentFolderName">The name of the folder containing the user configuration.</param> /// <param name="properties">The properties to load.</param> /// <returns>A user configuration instance.</returns> public static UserConfiguration Bind( ExchangeService service, string name, WellKnownFolderName parentFolderName, UserConfigurationProperties properties) { return UserConfiguration.Bind( service, name, new FolderId(parentFolderName), properties); }
/// <summary> /// Saves the post reply in a specified folder. Calling this method results in a call to EWS. /// </summary> /// <param name="destinationFolderName">The name of the folder in which to save the post reply.</param> /// <returns>A PostItem representing the posted reply.</returns> public PostItem Save(WellKnownFolderName destinationFolderName) { return (PostItem)this.InternalCreate(new FolderId(destinationFolderName), null); }
/// <summary> /// Sends this e-mail message and saves a copy of it in the specified folder. SendAndSaveCopy does not work if the /// message has unsaved attachments. In that case, the message must first be saved and then sent. Calling this method /// results in a call to EWS. /// </summary> /// <param name="destinationFolderName">The name of the folder in which to save the copy.</param> public void SendAndSaveCopy(WellKnownFolderName destinationFolderName) { this.InternalSend(new FolderId(destinationFolderName), MessageDisposition.SendAndSaveCopy); }
/// <summary> /// Sends async this e-mail message and saves a copy of it in the specified folder. SendAndSaveCopy does not work if the /// message has unsaved attachments. In that case, the message must first be saved and then sent. Calling this method /// results in a call to EWS. /// </summary> /// <param name="destinationFolderName">The name of the folder in which to save the copy.</param> public async System.Threading.Tasks.Task SendAndSaveCopyAsync(WellKnownFolderName destinationFolderName) { await this.InternalSendAsync(new FolderId(destinationFolderName), MessageDisposition.SendAndSaveCopy); }
/// <summary> /// Moves this item to a the specified folder. Calling this method results in a call to EWS. /// <para> /// Move returns null if the move operation is across two mailboxes or between a mailbox and a /// public folder. /// </para> /// </summary> /// <param name="destinationFolderName">The name of the folder to which to move this item.</param> /// <returns>The moved copy of this item.</returns> public Item Move(WellKnownFolderName destinationFolderName) { return this.Move(new FolderId(destinationFolderName)); }
/// <summary> /// Saves this item in a specific folder. Calling this method results in at least one call to EWS. /// Mutliple calls to EWS might be made if attachments have been added. /// </summary> /// <param name="parentFolderName">The name of the folder in which to save this item.</param> public async System.Threading.Tasks.Task SaveAsync(WellKnownFolderName parentFolderName) { await this.InternalCreateAsync( new FolderId(parentFolderName), MessageDisposition.SaveOnly, null); }
/// <summary> /// Initializes a new instance of the <see cref="FolderId"/> class. Use this constructor /// to link this FolderId to a well known folder (e.g. Inbox, Calendar or Contacts). /// </summary> /// <param name="folderName">The folder name used to initialize the FolderId.</param> public FolderId(WellKnownFolderName folderName) : base() { this.folderName = folderName; }
/// <summary> /// Initializes a new instance of the <see cref="FolderId"/> class. Use this constructor /// to link this FolderId to a well known folder (e.g. Inbox, Calendar or Contacts) in a /// specific mailbox. /// </summary> /// <param name="folderName">The folder name used to initialize the FolderId.</param> /// <param name="mailbox">The mailbox used to initialize the FolderId.</param> public FolderId(WellKnownFolderName folderName, Mailbox mailbox) : this(folderName) { this.mailbox = mailbox; }
/// <summary> /// Extract a calendar folder from the specified folder. /// </summary> /// <param name="WebService">Exchange Web Service instance to use</param> /// <param name="RootFolder">The location of the calendar to retrieve.</param> /// <param name="FolderPath">Path of the calendar folder within the Public Folder folder to find.</param> /// <exception cref="System.Exception">Could not find folder, or folder found is not a calendar.</exception> /// <returns>CalenderFolder object corresponding to the requested calendar (or null if not found).</returns> public static CalendarFolder GetCalendarFolder(ExchangeService WebService, WellKnownFolderName RootFolder, string FolderPath) { if (RootFolder != WellKnownFolderName.Calendar && RootFolder != WellKnownFolderName.PublicFoldersRoot) { throw new ArgumentException("FolderRoot must be either Calendar or PublicFoldersRoot", "FolderRoot"); } // Get the root well-known folder to look in. Folder FolderRoot = Folder.Bind(WebService, RootFolder); // Split the path of the folder we want to find on "\", and load it into an array (effectively of sub-folders) string[] SplitFolderPath = FolderPath.Split('\\'); // Get the FolderID of the well-known root folder. FolderId fId = FolderRoot.Id; // For each of the folders in the path, extract it foreach (string subFolderName in SplitFolderPath) { // Find the FolderID of the folder we're looking for. fId = FindFolder(WebService, fId, subFolderName); // If we couldn't find it, error... if (fId == null) { throw new Exception(string.Format("Can't find public folder {0}", FolderPath)); } } // Get the FolderID of the folder we settled on. Folder folderFound = Folder.Bind(WebService, fId); // Check the folder we found is a calendar - if not, error if (String.Compare(folderFound.FolderClass, "IPF.Appointment", StringComparison.Ordinal) != 0) { throw new Exception(string.Format("Public folder {0} is not a Calendar", FolderPath)); } // Bind the folder we found as a calendar folder CalendarFolder Calendar = CalendarFolder.Bind(WebService, fId, BasePropertySet.FirstClassProperties); // Done. return Calendar; }
/// <summary> /// Binds to an existing calendar folder and loads its first class properties. /// Calling this method results in a call to EWS. /// </summary> /// <param name="service">The service to use to bind to the calendar folder.</param> /// <param name="name">The name of the calendar folder to bind to.</param> /// <returns>A CalendarFolder instance representing the calendar folder with the specified name.</returns> public static new CalendarFolder Bind(ExchangeService service, WellKnownFolderName name) { return CalendarFolder.Bind( service, new FolderId(name), PropertySet.FirstClassProperties); }
/// <summary> /// Creates a copy of this item in the specified folder. Calling this method results in a call to EWS. /// <para> /// Copy returns null if the copy operation is across two mailboxes or between a mailbox and a /// public folder. /// </para> /// </summary> /// <param name="destinationFolderName">The name of the folder in which to create a copy of this item.</param> /// <returns>The copy of this item.</returns> public Item Copy(WellKnownFolderName destinationFolderName) { return this.Copy(new FolderId(destinationFolderName)); }
private List<MailItem> SearchSubFolders(ExchangeService service, WellKnownFolderName parentFolder, MailSearchContainerNameList subFolderNames, string mailBoxName, SearchFilter.SearchFilterCollection searchFilters) { var result = new List<MailItem>(); try { var subFolders = FindSubFolders(service, parentFolder, subFolderNames); if (subFolders == null || subFolders.Count() <= 0) return result; var itemView = new ItemView(VIEW_SIZE); itemView.PropertySet = new PropertySet {ItemSchema.Id, ItemSchema.HasAttachments, ItemSchema.Subject, ItemSchema.Body}; foreach (var subFolder in subFolders) { var matches = service.FindItems(subFolder.Id, searchFilters, itemView); AddItems(service, matches, result,mailBoxName,subFolder.DisplayName); } } catch (Exception ex) { //Ignore Debug.WriteLine(string.Format("Error encountered searching subfolders: {0}\n {1}", ex.ToString(), ex.StackTrace.ToString())); } return result; }
/// <summary> /// Moves this item to a the specified folder. Calling this method results in a call to EWS. /// <para> /// Move returns null if the move operation is across two mailboxes or between a mailbox and a /// public folder. /// </para> /// </summary> /// <param name="destinationFolderName">The name of the folder to which to move this item.</param> /// <returns>The moved copy of this item.</returns> public async System.Threading.Tasks.Task<Item> MoveAsync(WellKnownFolderName destinationFolderName) { return await this.MoveAsync(new FolderId(destinationFolderName)); }
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; }
private FindFoldersResults FindSubFolders(ExchangeService service, WellKnownFolderName parentFolder, MailSearchContainerNameList subFolderNames) { var folderView = new FolderView(VIEW_SIZE); folderView.PropertySet = new PropertySet(BasePropertySet.IdOnly, new PropertySet { FolderSchema.DisplayName, FolderSchema.Id }); Folder rootFolder = Folder.Bind(service, parentFolder); var searchFilters = new List<SearchFilter>(); foreach (var subfolderName in subFolderNames) { searchFilters.Add(new SearchFilter.ContainsSubstring(FolderSchema.DisplayName,subfolderName)); } var searchFilterCollection = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, searchFilters); return rootFolder.FindFolders(searchFilterCollection, folderView); }
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; }
/// <summary> /// Retreives well known folder id (Inbox, SentItems...) /// </summary> /// <param name="wellKnownFolderName">Wellknownfolder</param> /// <returns></returns> public static FolderId GetWellKnownFolderId(WellKnownFolderName wellKnownFolderName) { return new FolderId(wellKnownFolderName); }