diff --git a/README.md b/README.md index 71103908..3fe35d5f 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,10 @@ Examples are organized by feature category: - `programming-email-verification/` - 12 example(s) - `programming-with-gmail/` - 41 example(s) - `working-with-amp-html-emails/` - 16 example(s) -- `working-with-exchange-ews-client/` - 132 example(s) +- `working-with-exchange-ews-client/` - 140 example(s) - `working-with-exchange-webdav-client/` - 36 example(s) - `working-with-ibm-notes/` - 28 example(s) -- `working-with-imap-client/` - 57 example(s) +- `working-with-imap-client/` - 58 example(s) - `working-with-microsoft-graph-client/` - 27 example(s) - `working-with-mime-messages/` - 118 example(s) - `working-with-outlook-storage-files/` - 54 example(s) diff --git a/agents.md b/agents.md index 752c6ccf..e975291f 100644 --- a/agents.md +++ b/agents.md @@ -18,17 +18,17 @@ When working in this repository: - Follow the conventions and anti-patterns below exactly. ## Repository Overview -This repository currently contains **620** working code examples across **14** categories. +This repository currently contains **629** working code examples across **14** categories. ### Category Details - **convert-between-formats** — 39 examples. Guide: [agents.md](./convert-between-formats/agents.md) - **programming-email-verification** — 12 examples. Guide: [agents.md](./programming-email-verification/agents.md) - **programming-with-gmail** — 41 examples. Guide: [agents.md](./programming-with-gmail/agents.md) - **working-with-amp-html-emails** — 16 examples. Guide: [agents.md](./working-with-amp-html-emails/agents.md) -- **working-with-exchange-ews-client** — 132 examples. Guide: [agents.md](./working-with-exchange-ews-client/agents.md) +- **working-with-exchange-ews-client** — 140 examples. Guide: [agents.md](./working-with-exchange-ews-client/agents.md) - **working-with-exchange-webdav-client** — 36 examples. Guide: [agents.md](./working-with-exchange-webdav-client/agents.md) - **working-with-ibm-notes** — 28 examples. Guide: [agents.md](./working-with-ibm-notes/agents.md) -- **working-with-imap-client** — 57 examples. Guide: [agents.md](./working-with-imap-client/agents.md) +- **working-with-imap-client** — 58 examples. Guide: [agents.md](./working-with-imap-client/agents.md) - **working-with-microsoft-graph-client** — 27 examples. Guide: [agents.md](./working-with-microsoft-graph-client/agents.md) - **working-with-mime-messages** — 118 examples. Guide: [agents.md](./working-with-mime-messages/agents.md) - **working-with-outlook-storage-files** — 54 examples. Guide: [agents.md](./working-with-outlook-storage-files/agents.md) @@ -63,5 +63,5 @@ Success = exit code 0 and no `CS####` compiler errors. | Date | Run ID | Branch/Commit | |------|--------|---------------| -| 2026-03-28 | `20260328_182303` | examples/batch-20260328_182303 | +| 2026-03-31 | `20260331_043219` | [examples/batch-20260331_043219](https://github.com/aspose-email/agentic-net-examples/tree/examples/batch-20260331_043219) | \ No newline at end of file diff --git a/convert-between-formats/agents.md b/convert-between-formats/agents.md index 7eb52540..9e40408d 100644 --- a/convert-between-formats/agents.md +++ b/convert-between-formats/agents.md @@ -84,5 +84,5 @@ See the root [agents.md](../agents.md) for repository-wide conventions. | Date | Run ID | Branch/Commit | |------|--------|---------------| -| 2026-03-28 | `20260328_182303` | examples/batch-20260328_182303 | +| 2026-03-31 | `20260331_043219` | [examples/batch-20260331_043219](https://github.com/aspose-email/agentic-net-examples/tree/examples/batch-20260331_043219) | \ No newline at end of file diff --git a/index.json b/index.json index 1d4b5b97..98046be3 100644 --- a/index.json +++ b/index.json @@ -3,9 +3,9 @@ "platform": "net", "framework": "net8.0", "package_version": "26.1.0", - "total_examples": 620, + "total_examples": 629, "total_categories": 14, - "last_updated": "2026-03-28", + "last_updated": "2026-03-31", "categories": [ { "name": "convert-between-formats", @@ -361,8 +361,10 @@ }, { "name": "working-with-exchange-ews-client", - "file_count": 132, + "file_count": 140, "files": [ + "12967.cs", + "12971.cs", "add-contacts-to-an-existing-distribution-list-by-specifying-member-identifiers-and-updating-the-list-accordingly.cs", "add-custom-metadata-properties-to-the-target-object-to-enable-extended-attribute-storage-for-downstream-processing.cs", "add-the-required-email-library-package-to-the-project-using-the-nuget-package-manager.cs", @@ -387,11 +389,13 @@ "configure-the-service-s-authentication-credentials-to-enable-authorized-access-for-subsequent-programmatic-api-operations.cs", "configure-the-shared-mailbox-address-for-email-operations-to-direct-messages-to-the-designated-shared-account.cs", "connect-to-the-mail-server-and-retrieve-items-from-a-specific-mailbox-folder-using-the-provided-api.cs", + "construct-a-searchfiltercollection-that-merges-several-individual-filters-by-applying-the-logicaloperator-and-oper.cs", "construct-aqs-queries-to-filter-items-using-supported-operators-and-criteria-within-the-application.cs", "construct-complex-search-queries-by-combining-keywords-using-and-and-or-logical-operators-appropriately.cs", "create-a-new-appointment-instance-using-its-constructor-then-configure-required-event-properties-appropriately.cs", "create-a-new-archive-directory-or-determine-the-existing-one-for-storing-email-assets.cs", "create-a-new-contact-entry-in-the-address-book-with-specified-fields-and-persist-it.cs", + "create-a-new-contact-entry-within-the-address-book-ensuring-all-required-fields-are-correctly-populated.cs", "create-a-new-directory-within-the-file-system-ensuring-proper-path-handling-and-comprehensive-error-checking.cs", "create-a-new-distribution-list-and-programmatically-add-specified-recipients-for-bulk-email-sending.cs", "create-a-new-instance-of-the-distributionlist-class-for-managing-email-distribution-groups-within-your-application.cs", @@ -405,6 +409,7 @@ "create-modify-or-delete-distribution-lists-on-an-exchange-server-using-the-provided-api.cs", "delete-selected-email-messages-from-a-mailbox-ensuring-they-are-permanently-removed-and-synchronization-updates-accordingly.cs", "display-the-generated-log-output-in-the-console-or-designated-ui-component-for-diagnostic-review.cs", + "employ-asynchronous-apis-such-as-finditemsasync-to-fetch-email-messages-efficiently-allowing-non-blocking-operatio.cs", "enable-autodiscover-to-programmatically-resolve-the-ews-endpoint-url-using-the-user-s-email-address.cs", "enable-creation-retrieval-updating-and-deletion-of-exchange-server-mailbox-rules-through-the-exchange-web-services-interface.cs", "enable-diagnostic-tracing-for-the-service-at-runtime-by-assigning-true-to-its-traceenabled-property.cs", @@ -434,6 +439,7 @@ "instantiate-a-distribution-list-object-and-populate-it-with-specified-contacts-using-the-provided-api-methods.cs", "instantiate-an-exchange-service-object-configured-for-the-target-server-authentication-parameters-and-session-settings.cs", "instantiate-an-exchangeservice-object-to-interact-with-the-mail-server-programmatically-within-your-application.cs", + "instantiate-an-extendedproperty-object-using-a-specified-propertydefinition-to-associate-custom-metadata-within-th.cs", "instantiate-an-oauthcredentials-object-by-supplying-the-access-token-enabling-secure-authenticated-api-requests.cs", "instantiate-and-configure-a-new-task-object-to-perform-the-desired-operation-within-the-library.cs", "instantiate-the-exchangeservice-class-configure-its-credentials-and-establish-a-connection-to-the-exchange-server.cs", @@ -459,6 +465,7 @@ "optionally-configure-an-inbox-rule-that-automatically-archives-received-messages-based-on-defined-criteria.cs", "perform-an-aqs-query-against-the-data-source-to-retrieve-matching-items-using-specified-criteria.cs", "perform-asynchronous-email-retrieval-to-fetch-messages-without-blocking-the-calling-thread-supporting-cancellation-tokens-and.cs", + "perform-contact-management-operations-on-an-exchange-server-via-the-exchange-web-services-protocol.cs", "perform-folder-operations-on-an-exchange-server-including-creation-retrieval-updating-and-deletion-via-api.cs", "programmatically-define-and-configure-inbox-rules-to-automate-email-handling-based-on-specified-criteria.cs", "read-and-access-message-properties-including-sender-recipients-subject-and-custom-fields-using-the-net-library.cs", @@ -492,6 +499,7 @@ "specify-the-file-system-location-where-the-library-writes-its-log-files-for-troubleshooting-and-diagnostics.cs", "transfer-a-directory-and-its-contents-to-a-new-location-updating-all-internal-file-references-accordingly.cs", "update-or-customize-predefined-validation-rules-within-the-library-s-rule-engine-to-meet-specific-requirements.cs", + "use-the-addmember-method-to-insert-new-members-into-the-collection-ensuring-proper-initialization-and-validation.cs", "use-the-ews-api-to-fetch-email-messages-from-a-shared-mailbox-handling-authentication-and-folder-access.cs", "use-the-service-deletefolder-method-to-remove-the-specified-target-folder-from-the-storage-system.cs", "utilize-the-service-createitem-method-to-programmatically-instantiate-a-new-list-on-the-server-side-repository.cs" @@ -499,39 +507,39 @@ "required_namespaces": [ { "name": "System", - "count": 132 + "count": 140 }, { "name": "Aspose.Email", - "count": 122 + "count": 129 }, { "name": "Aspose.Email.Clients.Exchange.WebService", - "count": 108 + "count": 115 }, { "name": "System.Net", - "count": 95 + "count": 103 }, { "name": "Aspose.Email.Clients.Exchange", - "count": 71 + "count": 74 }, { "name": "System.IO", - "count": 20 + "count": 21 }, { "name": "Aspose.Email.Tools.Search", - "count": 14 + "count": 15 }, { - "name": "Aspose.Email.Clients", - "count": 12 + "name": "System.Collections.Generic", + "count": 13 }, { - "name": "System.Collections.Generic", - "count": 12 + "name": "Aspose.Email.Clients", + "count": 10 }, { "name": "Aspose.Email.Clients.Google", @@ -542,35 +550,31 @@ "count": 7 }, { - "name": "Aspose.Email.Mapi", + "name": "Aspose.Email.PersonalInfo", "count": 4 }, { "name": "System.Threading.Tasks", - "count": 3 + "count": 4 }, { - "name": "Aspose.Email.PersonalInfo", - "count": 2 + "name": "Aspose.Email.Mapi", + "count": 4 }, { - "name": "System.Linq", - "count": 2 + "name": "System.Threading", + "count": 3 }, { "name": "System.Text", - "count": 2 - }, - { - "name": "System.Text.Json", - "count": 2 + "count": 3 }, { - "name": "System.Threading", + "name": "System.Linq", "count": 2 }, { - "name": "Aspose.Email.Clients.Imap", + "name": "System.Text.Json", "count": 2 }, { @@ -581,9 +585,17 @@ "name": "Aspose.Email.Clients.Smtp", "count": 1 }, + { + "name": "System.ComponentModel", + "count": 1 + }, { "name": "Aspose.Email.Clients.Exchange.WebService.Models", "count": 1 + }, + { + "name": "Aspose.Email.Clients.Imap", + "count": 1 } ], "key_apis": [] @@ -648,7 +660,7 @@ }, { "name": "System.Net", - "count": 15 + "count": 16 }, { "name": "System.IO", @@ -675,12 +687,12 @@ "count": 4 }, { - "name": "Aspose.Email.Clients.Exchange.WebService", + "name": "Aspose.Email.Mapi", "count": 3 }, { - "name": "Aspose.Email.Mapi", - "count": 3 + "name": "Aspose.Email.Clients.Exchange.WebService", + "count": 2 }, { "name": "Aspose.Email.Clients.Smtp", @@ -760,7 +772,7 @@ }, { "name": "working-with-imap-client", - "file_count": 57, + "file_count": 58, "files": [ "activate-client-side-logging-by-setting-the-loggingenabled-boolean-property-to-true-on-the-client-instance.cs", "activate-detailed-imap-activity-logging-to-capture-all-client-server-interactions-for-diagnostics-and-auditing.cs", @@ -811,6 +823,7 @@ "remove-the-specified-directory-from-the-file-system-ensuring-all-contained-files-are-permanently-deleted.cs", "retrieve-and-display-imap-server-activity-logs-for-monitoring-connection-and-command-events-including-authentication.cs", "retrieve-and-interpret-flag-properties-of-email-messages-using-the-api-to-determine-each-message-s-status.cs", + "retrieve-email-messages-asynchronously-by-invoking-the-client-fetchmessagesasync-method-handling-the-returned-task-appropr.cs", "retrieve-email-messages-from-an-imap-server-using-appropriate-authentication-and-mailbox-selection-parameters.cs", "set-up-imap-protocol-logging-to-capture-client-server-communication-details-and-enable-diagnostic-analysis.cs", "transfer-email-messages-between-imap-folders-programmatically-ensuring-proper-synchronization-state-updates-and-efficient.cs", @@ -823,23 +836,23 @@ "required_namespaces": [ { "name": "System", - "count": 57 + "count": 58 }, { "name": "Aspose.Email.Clients", - "count": 52 + "count": 53 }, { "name": "Aspose.Email", - "count": 52 + "count": 53 }, { "name": "Aspose.Email.Clients.Imap", - "count": 52 + "count": 53 }, { "name": "Aspose.Email.Tools.Search", - "count": 23 + "count": 22 }, { "name": "System.IO", @@ -847,11 +860,11 @@ }, { "name": "System.Collections.Generic", - "count": 8 + "count": 9 }, { "name": "System.Threading.Tasks", - "count": 5 + "count": 6 }, { "name": "System.Threading", @@ -865,6 +878,10 @@ "name": "Aspose.Email.Clients.Google", "count": 2 }, + { + "name": "System.Net", + "count": 1 + }, { "name": "System.Linq", "count": 1 @@ -927,18 +944,18 @@ }, { "name": "System.IO", - "count": 23 + "count": 22 }, { "name": "Aspose.Email.Mapi", "count": 11 }, { - "name": "Aspose.Email.Clients.Exchange", - "count": 2 + "name": "System.Collections.Generic", + "count": 3 }, { - "name": "System.Collections.Generic", + "name": "Aspose.Email.Clients.Exchange", "count": 2 }, { diff --git a/programming-email-verification/agents.md b/programming-email-verification/agents.md index 9b00b830..3f370ce0 100644 --- a/programming-email-verification/agents.md +++ b/programming-email-verification/agents.md @@ -51,5 +51,5 @@ See the root [agents.md](../agents.md) for repository-wide conventions. | Date | Run ID | Branch/Commit | |------|--------|---------------| -| 2026-03-28 | `20260328_182303` | examples/batch-20260328_182303 | +| 2026-03-31 | `20260331_043219` | [examples/batch-20260331_043219](https://github.com/aspose-email/agentic-net-examples/tree/examples/batch-20260331_043219) | \ No newline at end of file diff --git a/programming-with-gmail/agents.md b/programming-with-gmail/agents.md index f0ba222d..890bb51e 100644 --- a/programming-with-gmail/agents.md +++ b/programming-with-gmail/agents.md @@ -98,5 +98,5 @@ See the root [agents.md](../agents.md) for repository-wide conventions. | Date | Run ID | Branch/Commit | |------|--------|---------------| -| 2026-03-28 | `20260328_182303` | examples/batch-20260328_182303 | +| 2026-03-31 | `20260331_043219` | [examples/batch-20260331_043219](https://github.com/aspose-email/agentic-net-examples/tree/examples/batch-20260331_043219) | \ No newline at end of file diff --git a/working-with-amp-html-emails/agents.md b/working-with-amp-html-emails/agents.md index ff1d457e..2ebc7511 100644 --- a/working-with-amp-html-emails/agents.md +++ b/working-with-amp-html-emails/agents.md @@ -59,5 +59,5 @@ See the root [agents.md](../agents.md) for repository-wide conventions. | Date | Run ID | Branch/Commit | |------|--------|---------------| -| 2026-03-28 | `20260328_182303` | examples/batch-20260328_182303 | +| 2026-03-31 | `20260331_043219` | [examples/batch-20260331_043219](https://github.com/aspose-email/agentic-net-examples/tree/examples/batch-20260331_043219) | \ No newline at end of file diff --git a/working-with-exchange-ews-client/12967.cs b/working-with-exchange-ews-client/12967.cs new file mode 100644 index 00000000..fd887888 --- /dev/null +++ b/working-with-exchange-ews-client/12967.cs @@ -0,0 +1,55 @@ +using System; +using System.Net; +using Aspose.Email; +using Aspose.Email.Clients.Exchange.WebService; +using Aspose.Email.Clients.Exchange; + +class Program +{ + static void Main() + { + try + { + // Placeholder connection details + string mailboxUri = "https://exchange.example.com/EWS/Exchange.asmx"; + string username = "user@example.com"; + string password = "password"; + + // Skip execution when using placeholder credentials/host + if (mailboxUri.Contains("example.com") || username.Contains("example.com")) + { + Console.Error.WriteLine("Placeholder credentials detected. Skipping EWS operation."); + return; + } + + // Create EWS client safely + try + { + using (IEWSClient client = EWSClient.GetEWSClient(mailboxUri, username, password)) + { + // Build an inbox rule that forwards all incoming messages + InboxRule rule = new InboxRule + { + DisplayName = "Auto Forward Rule", + IsEnabled = true, + Actions = new RuleActions() + }; + rule.Actions.ForwardToRecipients.Add(new MailAddress("forwardto@example.com")); + + // Create the rule on the server + client.CreateInboxRule(rule); + Console.WriteLine("Inbox rule created successfully."); + } + } + catch (Exception ex) + { + Console.Error.WriteLine($"EWS operation failed: {ex.Message}"); + return; + } + } + catch (Exception ex) + { + Console.Error.WriteLine($"Unexpected error: {ex.Message}"); + } + } +} diff --git a/working-with-exchange-ews-client/12971.cs b/working-with-exchange-ews-client/12971.cs new file mode 100644 index 00000000..3fedd882 --- /dev/null +++ b/working-with-exchange-ews-client/12971.cs @@ -0,0 +1,60 @@ +using System; +using System.Net; +using Aspose.Email; +using Aspose.Email.Clients.Exchange.WebService; + +class Program +{ + static void Main() + { + try + { + // Placeholder connection details – real values should be provided in production. + string serverUrl = "https://exchange.example.com/EWS/Exchange.asmx"; + string username = "username"; + string password = "password"; + + // Skip execution when placeholders are detected to avoid unwanted network calls. + if (serverUrl.Contains("example.com") || username == "username") + { + Console.WriteLine("Placeholder credentials detected. Skipping EWS operations."); + return; + } + + // Create and authenticate the EWS client. + using (IEWSClient client = EWSClient.GetEWSClient(serverUrl, new NetworkCredential(username, password))) + { + // -------------------- Create a new task -------------------- + ExchangeTask newTask = new ExchangeTask(); + newTask.Subject = "Sample Task"; + newTask.Body = "This is a sample task created via Aspose.Email."; + newTask.DueDate = DateTime.Now.AddDays(7); + + // CreateTask returns the task URI. + string taskUri = client.CreateTask(newTask); + Console.WriteLine($"Task created. Uri: {taskUri}"); + + // -------------------- Retrieve the task -------------------- + // FetchTask expects a task URI; after fetching we obtain the UniqueId. + ExchangeTask fetchedTask = client.FetchTask(taskUri); + string uniqueId = fetchedTask.UniqueId; + Console.WriteLine($"Fetched task UniqueId: {uniqueId}"); + + // -------------------- Update the task -------------------- + fetchedTask.Body = "Updated body content."; + client.UpdateTask(fetchedTask); + Console.WriteLine("Task updated."); + + // -------------------- Delete the task -------------------- + // Deletion must use the UniqueId, not the UniqueUri. + DeletionOptions deleteOptions = new DeletionOptions(DeletionType.MoveToDeletedItems); + client.DeleteItem(uniqueId, deleteOptions); + Console.WriteLine("Task deleted."); + } + } + catch (Exception ex) + { + Console.Error.WriteLine($"Error: {ex.Message}"); + } + } +} diff --git a/working-with-exchange-ews-client/add-contacts-to-an-existing-distribution-list-by-specifying-member-identifiers-and-updating-the-list-accordingly.cs b/working-with-exchange-ews-client/add-contacts-to-an-existing-distribution-list-by-specifying-member-identifiers-and-updating-the-list-accordingly.cs index f5debf39..31257986 100644 --- a/working-with-exchange-ews-client/add-contacts-to-an-existing-distribution-list-by-specifying-member-identifiers-and-updating-the-list-accordingly.cs +++ b/working-with-exchange-ews-client/add-contacts-to-an-existing-distribution-list-by-specifying-member-identifiers-and-updating-the-list-accordingly.cs @@ -1,7 +1,6 @@ using System; using System.Net; using Aspose.Email; -using Aspose.Email.Clients; using Aspose.Email.Clients.Exchange; using Aspose.Email.Clients.Exchange.WebService; @@ -11,33 +10,41 @@ static void Main(string[] args) { try { - // Initialize credentials for the Exchange server - NetworkCredential credential = new NetworkCredential("username", "password"); + // Placeholder credentials – replace with real values or skip execution. + string mailboxUri = "https://exchange.example.com/EWS/Exchange.asmx"; + string username = "user@example.com"; + string password = "password"; - // Create the EWS client inside a using block to ensure proper disposal - try + // Guard against running with placeholder data. + if (mailboxUri.Contains("example.com") || username.Contains("example.com") || password == "password") { - using (IEWSClient client = EWSClient.GetEWSClient("https://exchange.example.com/EWS/Exchange.asmx", credential)) + Console.Error.WriteLine("Placeholder credentials detected. Skipping execution."); + return; + } + + // Create the EWS client. + using (IEWSClient client = EWSClient.GetEWSClient(mailboxUri, username, password)) + { + try { - // Identify the existing distribution list by its Id + // Identify the distribution list to update (use actual Id). ExchangeDistributionList distributionList = new ExchangeDistributionList(); - distributionList.Id = "distribution-list-id"; + distributionList.Id = "distributionlist-id"; - // Prepare the collection of new members to add + // Prepare the members to add. MailAddressCollection members = new MailAddressCollection(); members.Add(new MailAddress("newmember1@example.com")); members.Add(new MailAddress("newmember2@example.com")); - // Append the new members to the distribution list + // Add members to the distribution list. client.AddToDistributionList(distributionList, members); - - Console.WriteLine("Members added to the distribution list successfully."); + Console.WriteLine("Members added to distribution list successfully."); + } + catch (Exception ex) + { + Console.Error.WriteLine($"Error updating distribution list: {ex.Message}"); + return; } - } - catch (Exception ex) - { - Console.Error.WriteLine($"EWS operation failed: {ex.Message}"); - return; } } catch (Exception ex) diff --git a/working-with-exchange-ews-client/agents.md b/working-with-exchange-ews-client/agents.md index fcebb9c6..c8262029 100644 --- a/working-with-exchange-ews-client/agents.md +++ b/working-with-exchange-ews-client/agents.md @@ -18,32 +18,35 @@ See the root [agents.md](../agents.md) for repository-wide conventions. - Files are standalone `.cs` examples stored directly in this folder. ## Required Namespaces -- `using System;` (132 file(s)) -- `using Aspose.Email;` (122 file(s)) -- `using Aspose.Email.Clients.Exchange.WebService;` (108 file(s)) -- `using System.Net;` (95 file(s)) -- `using Aspose.Email.Clients.Exchange;` (71 file(s)) -- `using System.IO;` (20 file(s)) -- `using Aspose.Email.Tools.Search;` (14 file(s)) -- `using Aspose.Email.Clients;` (12 file(s)) -- `using System.Collections.Generic;` (12 file(s)) +- `using System;` (140 file(s)) +- `using Aspose.Email;` (129 file(s)) +- `using Aspose.Email.Clients.Exchange.WebService;` (115 file(s)) +- `using System.Net;` (103 file(s)) +- `using Aspose.Email.Clients.Exchange;` (74 file(s)) +- `using System.IO;` (21 file(s)) +- `using Aspose.Email.Tools.Search;` (15 file(s)) +- `using System.Collections.Generic;` (13 file(s)) +- `using Aspose.Email.Clients;` (10 file(s)) - `using Aspose.Email.Clients.Google;` (9 file(s)) - `using Aspose.Email.Calendar;` (7 file(s)) +- `using Aspose.Email.PersonalInfo;` (4 file(s)) +- `using System.Threading.Tasks;` (4 file(s)) - `using Aspose.Email.Mapi;` (4 file(s)) -- `using System.Threading.Tasks;` (3 file(s)) -- `using Aspose.Email.PersonalInfo;` (2 file(s)) +- `using System.Threading;` (3 file(s)) +- `using System.Text;` (3 file(s)) - `using System.Linq;` (2 file(s)) -- `using System.Text;` (2 file(s)) - `using System.Text.Json;` (2 file(s)) -- `using System.Threading;` (2 file(s)) -- `using Aspose.Email.Clients.Imap;` (2 file(s)) - `using System.IO.Compression;` (1 file(s)) - `using Aspose.Email.Clients.Smtp;` (1 file(s)) +- `using System.ComponentModel;` (1 file(s)) - `using Aspose.Email.Clients.Exchange.WebService.Models;` (1 file(s)) +- `using Aspose.Email.Clients.Imap;` (1 file(s)) ## Files in this folder | File | Description | |------|-------------| +| [12967.cs](./12967.cs) | 12967 | +| [12971.cs](./12971.cs) | 12971 | | [add-contacts-to-an-existing-distribution-list-by-specifying-member-identifiers-and-updating-the-list-accordingly.cs](./add-contacts-to-an-existing-distribution-list-by-specifying-member-identifiers-and-updating-the-list-accordingly.cs) | add contacts to an existing distribution list by specifying member identifiers and updating the list accordingly | | [add-custom-metadata-properties-to-the-target-object-to-enable-extended-attribute-storage-for-downstream-processing.cs](./add-custom-metadata-properties-to-the-target-object-to-enable-extended-attribute-storage-for-downstream-processing.cs) | add custom metadata properties to the target object to enable extended attribute storage for downstream processing | | [add-the-required-email-library-package-to-the-project-using-the-nuget-package-manager.cs](./add-the-required-email-library-package-to-the-project-using-the-nuget-package-manager.cs) | add the required email library package to the project using the nuget package manager | @@ -68,11 +71,13 @@ See the root [agents.md](../agents.md) for repository-wide conventions. | [configure-the-service-s-authentication-credentials-to-enable-authorized-access-for-subsequent-programmatic-api-operations.cs](./configure-the-service-s-authentication-credentials-to-enable-authorized-access-for-subsequent-programmatic-api-operations.cs) | configure the service s authentication credentials to enable authorized access for subsequent programmatic api operations | | [configure-the-shared-mailbox-address-for-email-operations-to-direct-messages-to-the-designated-shared-account.cs](./configure-the-shared-mailbox-address-for-email-operations-to-direct-messages-to-the-designated-shared-account.cs) | configure the shared mailbox address for email operations to direct messages to the designated shared account | | [connect-to-the-mail-server-and-retrieve-items-from-a-specific-mailbox-folder-using-the-provided-api.cs](./connect-to-the-mail-server-and-retrieve-items-from-a-specific-mailbox-folder-using-the-provided-api.cs) | connect to the mail server and retrieve items from a specific mailbox folder using the provided api | +| [construct-a-searchfiltercollection-that-merges-several-individual-filters-by-applying-the-logicaloperator-and-oper.cs](./construct-a-searchfiltercollection-that-merges-several-individual-filters-by-applying-the-logicaloperator-and-oper.cs) | construct a searchfiltercollection that merges several individual filters by applying the logicaloperator and oper | | [construct-aqs-queries-to-filter-items-using-supported-operators-and-criteria-within-the-application.cs](./construct-aqs-queries-to-filter-items-using-supported-operators-and-criteria-within-the-application.cs) | construct aqs queries to filter items using supported operators and criteria within the application | | [construct-complex-search-queries-by-combining-keywords-using-and-and-or-logical-operators-appropriately.cs](./construct-complex-search-queries-by-combining-keywords-using-and-and-or-logical-operators-appropriately.cs) | construct complex search queries by combining keywords using and and or logical operators appropriately | | [create-a-new-appointment-instance-using-its-constructor-then-configure-required-event-properties-appropriately.cs](./create-a-new-appointment-instance-using-its-constructor-then-configure-required-event-properties-appropriately.cs) | create a new appointment instance using its constructor then configure required event properties appropriately | | [create-a-new-archive-directory-or-determine-the-existing-one-for-storing-email-assets.cs](./create-a-new-archive-directory-or-determine-the-existing-one-for-storing-email-assets.cs) | create a new archive directory or determine the existing one for storing email assets | | [create-a-new-contact-entry-in-the-address-book-with-specified-fields-and-persist-it.cs](./create-a-new-contact-entry-in-the-address-book-with-specified-fields-and-persist-it.cs) | create a new contact entry in the address book with specified fields and persist it | +| [create-a-new-contact-entry-within-the-address-book-ensuring-all-required-fields-are-correctly-populated.cs](./create-a-new-contact-entry-within-the-address-book-ensuring-all-required-fields-are-correctly-populated.cs) | create a new contact entry within the address book ensuring all required fields are correctly populated | | [create-a-new-directory-within-the-file-system-ensuring-proper-path-handling-and-comprehensive-error-checking.cs](./create-a-new-directory-within-the-file-system-ensuring-proper-path-handling-and-comprehensive-error-checking.cs) | create a new directory within the file system ensuring proper path handling and comprehensive error checking | | [create-a-new-distribution-list-and-programmatically-add-specified-recipients-for-bulk-email-sending.cs](./create-a-new-distribution-list-and-programmatically-add-specified-recipients-for-bulk-email-sending.cs) | create a new distribution list and programmatically add specified recipients for bulk email sending | | [create-a-new-instance-of-the-distributionlist-class-for-managing-email-distribution-groups-within-your-application.cs](./create-a-new-instance-of-the-distributionlist-class-for-managing-email-distribution-groups-within-your-application.cs) | create a new instance of the distributionlist class for managing email distribution groups within your application | @@ -86,6 +91,7 @@ See the root [agents.md](../agents.md) for repository-wide conventions. | [create-modify-or-delete-distribution-lists-on-an-exchange-server-using-the-provided-api.cs](./create-modify-or-delete-distribution-lists-on-an-exchange-server-using-the-provided-api.cs) | create modify or delete distribution lists on an exchange server using the provided api | | [delete-selected-email-messages-from-a-mailbox-ensuring-they-are-permanently-removed-and-synchronization-updates-accordingly.cs](./delete-selected-email-messages-from-a-mailbox-ensuring-they-are-permanently-removed-and-synchronization-updates-accordingly.cs) | delete selected email messages from a mailbox ensuring they are permanently removed and synchronization updates accordingly | | [display-the-generated-log-output-in-the-console-or-designated-ui-component-for-diagnostic-review.cs](./display-the-generated-log-output-in-the-console-or-designated-ui-component-for-diagnostic-review.cs) | display the generated log output in the console or designated ui component for diagnostic review | +| [employ-asynchronous-apis-such-as-finditemsasync-to-fetch-email-messages-efficiently-allowing-non-blocking-operatio.cs](./employ-asynchronous-apis-such-as-finditemsasync-to-fetch-email-messages-efficiently-allowing-non-blocking-operatio.cs) | employ asynchronous apis such as finditemsasync to fetch email messages efficiently allowing non blocking operatio | | [enable-autodiscover-to-programmatically-resolve-the-ews-endpoint-url-using-the-user-s-email-address.cs](./enable-autodiscover-to-programmatically-resolve-the-ews-endpoint-url-using-the-user-s-email-address.cs) | enable autodiscover to programmatically resolve the ews endpoint url using the user s email address | | [enable-creation-retrieval-updating-and-deletion-of-exchange-server-mailbox-rules-through-the-exchange-web-services-interface.cs](./enable-creation-retrieval-updating-and-deletion-of-exchange-server-mailbox-rules-through-the-exchange-web-services-interface.cs) | enable creation retrieval updating and deletion of exchange server mailbox rules through the exchange web services interface | | [enable-diagnostic-tracing-for-the-service-at-runtime-by-assigning-true-to-its-traceenabled-property.cs](./enable-diagnostic-tracing-for-the-service-at-runtime-by-assigning-true-to-its-traceenabled-property.cs) | enable diagnostic tracing for the service at runtime by assigning true to its traceenabled property | @@ -115,6 +121,7 @@ See the root [agents.md](../agents.md) for repository-wide conventions. | [instantiate-a-distribution-list-object-and-populate-it-with-specified-contacts-using-the-provided-api-methods.cs](./instantiate-a-distribution-list-object-and-populate-it-with-specified-contacts-using-the-provided-api-methods.cs) | instantiate a distribution list object and populate it with specified contacts using the provided api methods | | [instantiate-an-exchange-service-object-configured-for-the-target-server-authentication-parameters-and-session-settings.cs](./instantiate-an-exchange-service-object-configured-for-the-target-server-authentication-parameters-and-session-settings.cs) | instantiate an exchange service object configured for the target server authentication parameters and session settings | | [instantiate-an-exchangeservice-object-to-interact-with-the-mail-server-programmatically-within-your-application.cs](./instantiate-an-exchangeservice-object-to-interact-with-the-mail-server-programmatically-within-your-application.cs) | instantiate an exchangeservice object to interact with the mail server programmatically within your application | +| [instantiate-an-extendedproperty-object-using-a-specified-propertydefinition-to-associate-custom-metadata-within-th.cs](./instantiate-an-extendedproperty-object-using-a-specified-propertydefinition-to-associate-custom-metadata-within-th.cs) | instantiate an extendedproperty object using a specified propertydefinition to associate custom metadata within th | | [instantiate-an-oauthcredentials-object-by-supplying-the-access-token-enabling-secure-authenticated-api-requests.cs](./instantiate-an-oauthcredentials-object-by-supplying-the-access-token-enabling-secure-authenticated-api-requests.cs) | instantiate an oauthcredentials object by supplying the access token enabling secure authenticated api requests | | [instantiate-and-configure-a-new-task-object-to-perform-the-desired-operation-within-the-library.cs](./instantiate-and-configure-a-new-task-object-to-perform-the-desired-operation-within-the-library.cs) | instantiate and configure a new task object to perform the desired operation within the library | | [instantiate-the-exchangeservice-class-configure-its-credentials-and-establish-a-connection-to-the-exchange-server.cs](./instantiate-the-exchangeservice-class-configure-its-credentials-and-establish-a-connection-to-the-exchange-server.cs) | instantiate the exchangeservice class configure its credentials and establish a connection to the exchange server | @@ -140,6 +147,7 @@ See the root [agents.md](../agents.md) for repository-wide conventions. | [optionally-configure-an-inbox-rule-that-automatically-archives-received-messages-based-on-defined-criteria.cs](./optionally-configure-an-inbox-rule-that-automatically-archives-received-messages-based-on-defined-criteria.cs) | optionally configure an inbox rule that automatically archives received messages based on defined criteria | | [perform-an-aqs-query-against-the-data-source-to-retrieve-matching-items-using-specified-criteria.cs](./perform-an-aqs-query-against-the-data-source-to-retrieve-matching-items-using-specified-criteria.cs) | perform an aqs query against the data source to retrieve matching items using specified criteria | | [perform-asynchronous-email-retrieval-to-fetch-messages-without-blocking-the-calling-thread-supporting-cancellation-tokens-and.cs](./perform-asynchronous-email-retrieval-to-fetch-messages-without-blocking-the-calling-thread-supporting-cancellation-tokens-and.cs) | perform asynchronous email retrieval to fetch messages without blocking the calling thread supporting cancellation tokens and | +| [perform-contact-management-operations-on-an-exchange-server-via-the-exchange-web-services-protocol.cs](./perform-contact-management-operations-on-an-exchange-server-via-the-exchange-web-services-protocol.cs) | perform contact management operations on an exchange server via the exchange web services protocol | | [perform-folder-operations-on-an-exchange-server-including-creation-retrieval-updating-and-deletion-via-api.cs](./perform-folder-operations-on-an-exchange-server-including-creation-retrieval-updating-and-deletion-via-api.cs) | perform folder operations on an exchange server including creation retrieval updating and deletion via api | | [programmatically-define-and-configure-inbox-rules-to-automate-email-handling-based-on-specified-criteria.cs](./programmatically-define-and-configure-inbox-rules-to-automate-email-handling-based-on-specified-criteria.cs) | programmatically define and configure inbox rules to automate email handling based on specified criteria | | [read-and-access-message-properties-including-sender-recipients-subject-and-custom-fields-using-the-net-library.cs](./read-and-access-message-properties-including-sender-recipients-subject-and-custom-fields-using-the-net-library.cs) | read and access message properties including sender recipients subject and custom fields using the net library | @@ -173,12 +181,13 @@ See the root [agents.md](../agents.md) for repository-wide conventions. | [specify-the-file-system-location-where-the-library-writes-its-log-files-for-troubleshooting-and-diagnostics.cs](./specify-the-file-system-location-where-the-library-writes-its-log-files-for-troubleshooting-and-diagnostics.cs) | specify the file system location where the library writes its log files for troubleshooting and diagnostics | | [transfer-a-directory-and-its-contents-to-a-new-location-updating-all-internal-file-references-accordingly.cs](./transfer-a-directory-and-its-contents-to-a-new-location-updating-all-internal-file-references-accordingly.cs) | transfer a directory and its contents to a new location updating all internal file references accordingly | | [update-or-customize-predefined-validation-rules-within-the-library-s-rule-engine-to-meet-specific-requirements.cs](./update-or-customize-predefined-validation-rules-within-the-library-s-rule-engine-to-meet-specific-requirements.cs) | update or customize predefined validation rules within the library s rule engine to meet specific requirements | +| [use-the-addmember-method-to-insert-new-members-into-the-collection-ensuring-proper-initialization-and-validation.cs](./use-the-addmember-method-to-insert-new-members-into-the-collection-ensuring-proper-initialization-and-validation.cs) | use the addmember method to insert new members into the collection ensuring proper initialization and validation | | [use-the-ews-api-to-fetch-email-messages-from-a-shared-mailbox-handling-authentication-and-folder-access.cs](./use-the-ews-api-to-fetch-email-messages-from-a-shared-mailbox-handling-authentication-and-folder-access.cs) | use the ews api to fetch email messages from a shared mailbox handling authentication and folder access | | [use-the-service-deletefolder-method-to-remove-the-specified-target-folder-from-the-storage-system.cs](./use-the-service-deletefolder-method-to-remove-the-specified-target-folder-from-the-storage-system.cs) | use the service deletefolder method to remove the specified target folder from the storage system | | [utilize-the-service-createitem-method-to-programmatically-instantiate-a-new-list-on-the-server-side-repository.cs](./utilize-the-service-createitem-method-to-programmatically-instantiate-a-new-list-on-the-server-side-repository.cs) | utilize the service createitem method to programmatically instantiate a new list on the server side repository | ## Category Statistics -- Total examples: 132 +- Total examples: 140 ## General Tips - Follow root boundaries and testing guide. @@ -187,5 +196,5 @@ See the root [agents.md](../agents.md) for repository-wide conventions. | Date | Run ID | Branch/Commit | |------|--------|---------------| -| 2026-03-28 | `20260328_182303` | examples/batch-20260328_182303 | +| 2026-03-31 | `20260331_043219` | [examples/batch-20260331_043219](https://github.com/aspose-email/agentic-net-examples/tree/examples/batch-20260331_043219) | \ No newline at end of file diff --git a/working-with-exchange-ews-client/construct-a-searchfiltercollection-that-merges-several-individual-filters-by-applying-the-logicaloperator-and-oper.cs b/working-with-exchange-ews-client/construct-a-searchfiltercollection-that-merges-several-individual-filters-by-applying-the-logicaloperator-and-oper.cs new file mode 100644 index 00000000..908bc3f0 --- /dev/null +++ b/working-with-exchange-ews-client/construct-a-searchfiltercollection-that-merges-several-individual-filters-by-applying-the-logicaloperator-and-oper.cs @@ -0,0 +1,41 @@ +using System; +using System.Net; +using Aspose.Email.Clients.Exchange.WebService; +using Aspose.Email.Tools.Search; + +class Program +{ + static void Main() + { + try + { + string serviceUrl = "https://exchange.example.com/EWS/Exchange.asmx"; + string username = "user@example.com"; + string password = "password"; + + if (serviceUrl.Contains("example.com") || username.Contains("example.com")) + { + Console.WriteLine("Placeholder credentials detected. Skipping execution."); + return; + } + + using (IEWSClient client = EWSClient.GetEWSClient(serviceUrl, new NetworkCredential(username, password))) + { + // Build a query with multiple conditions (logical AND). + MailQueryBuilder builder = new MailQueryBuilder(); + builder.Subject.Contains("Report"); + builder.InternalDate.Greater(DateTime.Parse("1-Jan-2023"), DateComparisonType.ByDate); + + MailQuery query = builder.GetQuery(); + + // List messages that satisfy all conditions. + var messages = client.ListMessages(client.MailboxInfo.InboxUri, query); + Console.WriteLine($"Matched {messages.Count} message(s)."); + } + } + catch (Exception ex) + { + Console.Error.WriteLine($"Error: {ex.Message}"); + } + } +} diff --git a/working-with-exchange-ews-client/create-a-new-contact-entry-in-the-address-book-with-specified-fields-and-persist-it.cs b/working-with-exchange-ews-client/create-a-new-contact-entry-in-the-address-book-with-specified-fields-and-persist-it.cs index eb7f71df..2f33a676 100644 --- a/working-with-exchange-ews-client/create-a-new-contact-entry-in-the-address-book-with-specified-fields-and-persist-it.cs +++ b/working-with-exchange-ews-client/create-a-new-contact-entry-in-the-address-book-with-specified-fields-and-persist-it.cs @@ -1,4 +1,5 @@ using System; +using System.Net; using Aspose.Email; using Aspose.Email.PersonalInfo; using Aspose.Email.Clients.Exchange.WebService; @@ -9,24 +10,38 @@ static void Main() { try { - // Initialize EWS client (replace placeholders with real values) - using (IEWSClient client = EWSClient.GetEWSClient("https://exchange.example.com/EWS/Exchange.asmx", "username", "password")) + string mailboxUri = "https://exchange.example.com/EWS/Exchange.asmx"; + string username = "username"; + string password = "password"; + + // Skip execution when placeholder credentials are detected + if (mailboxUri.Contains("example.com") || username == "username") + { + Console.WriteLine("Placeholder credentials detected. Skipping contact creation."); + return; + } + + // Create and connect the EWS client + using (IEWSClient client = EWSClient.GetEWSClient(mailboxUri, username, password)) { - // Create a new contact and set its properties - Contact contact = new Contact(); - contact.GivenName = "John"; - contact.Surname = "Doe"; - contact.CompanyName = "Example Corp"; - contact.EmailAddresses.Add(new EmailAddress("john.doe@example.com")); + // Build a new contact + Contact contact = new Contact + { + DisplayName = "John Doe", + GivenName = "John", + Surname = "Doe", + CompanyName = "Acme Corp" + }; + contact.EmailAddresses.Add(new EmailAddress("john.doe@acme.com", "John Doe")); - // Persist the contact to the Exchange store + // Create the contact on the Exchange server string contactUri = client.CreateContact(contact); - Console.WriteLine("Contact created: " + contactUri); + Console.WriteLine($"Contact created. URI: {contactUri}"); } } catch (Exception ex) { - Console.Error.WriteLine("Error: " + ex.Message); + Console.Error.WriteLine($"Error: {ex.Message}"); } } } diff --git a/working-with-exchange-ews-client/create-a-new-contact-entry-within-the-address-book-ensuring-all-required-fields-are-correctly-populated.cs b/working-with-exchange-ews-client/create-a-new-contact-entry-within-the-address-book-ensuring-all-required-fields-are-correctly-populated.cs new file mode 100644 index 00000000..3af40d36 --- /dev/null +++ b/working-with-exchange-ews-client/create-a-new-contact-entry-within-the-address-book-ensuring-all-required-fields-are-correctly-populated.cs @@ -0,0 +1,52 @@ +using System; +using System.Net; +using Aspose.Email; +using Aspose.Email.PersonalInfo; +using Aspose.Email.Clients.Exchange.WebService; + +class Program +{ + static void Main() + { + try + { + // Placeholder connection details + string mailboxUri = "https://exchange.example.com/EWS/Exchange.asmx"; + string username = "username"; + string password = "password"; + + // Skip execution when using placeholder credentials to avoid real network calls + if (mailboxUri.Contains("example.com") || username == "username" || password == "password") + { + Console.WriteLine("Placeholder credentials detected. Skipping contact creation."); + return; + } + + // Create and configure the EWS client + using (IEWSClient client = EWSClient.GetEWSClient(mailboxUri, username, password)) + { + try + { + // Build a new contact with required fields + Contact newContact = new Contact + { + DisplayName = "John Doe" + }; + newContact.EmailAddresses.Add(new EmailAddress("john.doe@example.com", "John Doe")); + + // Create the contact in the Exchange store + string contactUri = client.CreateContact(newContact); + Console.WriteLine($"Contact created successfully. URI: {contactUri}"); + } + catch (Exception ex) + { + Console.Error.WriteLine($"Error while creating contact: {ex.Message}"); + } + } + } + catch (Exception ex) + { + Console.Error.WriteLine($"Unhandled exception: {ex.Message}"); + } + } +} diff --git a/working-with-exchange-ews-client/create-a-new-rule-instance-then-configure-its-conditional-logic-and-associated-actions-accordingly.cs b/working-with-exchange-ews-client/create-a-new-rule-instance-then-configure-its-conditional-logic-and-associated-actions-accordingly.cs index a54d740e..18909db3 100644 --- a/working-with-exchange-ews-client/create-a-new-rule-instance-then-configure-its-conditional-logic-and-associated-actions-accordingly.cs +++ b/working-with-exchange-ews-client/create-a-new-rule-instance-then-configure-its-conditional-logic-and-associated-actions-accordingly.cs @@ -1,41 +1,57 @@ using System; -using System.Net; +using System.Collections.Generic; using Aspose.Email; -using Aspose.Email.Clients.Exchange.WebService; -using Aspose.Email.Clients.Exchange; -class Program +namespace AsposeEmailRuleSample { - static void Main() + // Simple rule class with condition and action + public class Rule { - try + public Func Condition { get; set; } + public Action Action { get; set; } + + public void Apply(MailMessage message) { - // Initialize EWS client safely - using (IEWSClient client = EWSClient.GetEWSClient( - "https://example.com/EWS/Exchange.asmx", - new NetworkCredential("username", "password"))) + if (Condition != null && Condition(message)) { - // Create a new inbox rule that deletes messages from a specific sender - InboxRule rule = InboxRule.CreateRuleDeleteFrom(new MailAddress("spam@example.com")); - rule.DisplayName = "Delete Spam Sender"; - rule.IsEnabled = true; - rule.Priority = 1; - - // Add the rule to the mailbox - client.CreateInboxRule(rule); - - // Retrieve and display all inbox rules - InboxRule[] rules = client.GetInboxRules(); - Console.WriteLine("Inbox Rules:"); - foreach (InboxRule r in rules) - { - Console.WriteLine($"- {r.DisplayName} (Enabled: {r.IsEnabled})"); - } + Action?.Invoke(message); } } - catch (Exception ex) + } + + class Program + { + static void Main(string[] args) { - Console.Error.WriteLine($"Error: {ex.Message}"); + try + { + // Create a sample mail message + MailMessage sampleMessage = new MailMessage(); + sampleMessage.From = "sender@example.com"; + sampleMessage.To.Add("recipient@example.com"); + sampleMessage.Subject = "Test Email"; + sampleMessage.Body = "This is a test email."; + + // Create a new rule instance + Rule moveToFolderRule = new Rule(); + + // Configure condition: subject contains "Test" + moveToFolderRule.Condition = (MailMessage msg) => msg.Subject != null && msg.Subject.Contains("Test"); + + // Configure action: add a custom header + moveToFolderRule.Action = (MailMessage msg) => msg.Headers.Add("X-Processed", "True"); + + // Apply rule to the message + moveToFolderRule.Apply(sampleMessage); + + // Output result + Console.WriteLine("Rule applied. Header X-Processed: " + sampleMessage.Headers["X-Processed"]); + } + catch (Exception ex) + { + Console.Error.WriteLine(ex.Message); + return; + } } } } diff --git a/working-with-exchange-ews-client/employ-asynchronous-apis-such-as-finditemsasync-to-fetch-email-messages-efficiently-allowing-non-blocking-operatio.cs b/working-with-exchange-ews-client/employ-asynchronous-apis-such-as-finditemsasync-to-fetch-email-messages-efficiently-allowing-non-blocking-operatio.cs new file mode 100644 index 00000000..89e62b85 --- /dev/null +++ b/working-with-exchange-ews-client/employ-asynchronous-apis-such-as-finditemsasync-to-fetch-email-messages-efficiently-allowing-non-blocking-operatio.cs @@ -0,0 +1,63 @@ +using System; +using System.Net; +using System.Threading; +using System.Threading.Tasks; +using System.Collections.Generic; +using System.ComponentModel; +using Aspose.Email; +using Aspose.Email.Clients.Exchange.WebService; +using Aspose.Email.Clients.Exchange; + +namespace AsposeEmailAsyncSample +{ + class Program + { + static async Task Main(string[] args) + { + try + { + // Placeholder credentials detection – skip execution in CI environments + string mailboxUri = "https://exchange.example.com/EWS/Exchange.asmx"; + NetworkCredential credentials = new NetworkCredential("username", "password"); + if (mailboxUri.Contains("example.com")) + { + Console.Error.WriteLine("Placeholder credentials detected. Skipping execution."); + return; + } + + // Initialize asynchronous EWS client + IAsyncEwsClient client = await EWSClient.GetEwsClientAsync(mailboxUri, credentials); + try + { + // Asynchronously list messages in the Inbox folder without a query (fetch all) + ExchangeMessageInfoCollection messages = await client.ListMessagesAsync( + folder: "Inbox", + mailbox: null, + maxNumberOfMessages: 0, + query: null, + recursive: false, + extendedProperties: null, + cancellationToken: CancellationToken.None); + + // Output basic information for each message + foreach (ExchangeMessageInfo messageInfo in messages) + { + Console.WriteLine($"Subject: {messageInfo.Subject}"); + } + } + finally + { + // Ensure client resources are released + if (client is IDisposable disposableClient) + { + disposableClient.Dispose(); + } + } + } + catch (Exception ex) + { + Console.Error.WriteLine($"Error: {ex.Message}"); + } + } + } +} diff --git a/working-with-exchange-ews-client/enable-creation-retrieval-updating-and-deletion-of-exchange-server-mailbox-rules-through-the-exchange-web-services-interface.cs b/working-with-exchange-ews-client/enable-creation-retrieval-updating-and-deletion-of-exchange-server-mailbox-rules-through-the-exchange-web-services-interface.cs index 879c41e1..5301c37f 100644 --- a/working-with-exchange-ews-client/enable-creation-retrieval-updating-and-deletion-of-exchange-server-mailbox-rules-through-the-exchange-web-services-interface.cs +++ b/working-with-exchange-ews-client/enable-creation-retrieval-updating-and-deletion-of-exchange-server-mailbox-rules-through-the-exchange-web-services-interface.cs @@ -3,68 +3,103 @@ using Aspose.Email.Clients.Exchange; using Aspose.Email.Clients.Exchange.WebService; -class Program +namespace AsposeEmailEwsInboxRuleSample { - static void Main() + class Program { - try + static void Main(string[] args) { - // Initialize the EWS client (connection safety) - using (IEWSClient client = EWSClient.GetEWSClient("https://exchange.example.com/EWS/Exchange.asmx", "username", "password")) + // Top‑level exception guard + try { - try + // Placeholder connection information + string mailboxUri = "https://exchange.example.com/EWS/Exchange.asmx"; + string username = "username"; + string password = "password"; + + // Skip real network calls when placeholders are detected + if (mailboxUri.Contains("example.com") || + username.Equals("username", StringComparison.OrdinalIgnoreCase) || + password.Equals("password", StringComparison.OrdinalIgnoreCase)) { - // -------------------- Create a new inbox rule -------------------- - InboxRule newRule = new InboxRule(); - newRule.DisplayName = "Sample Rule"; - newRule.IsEnabled = true; - client.CreateInboxRule(newRule); - Console.WriteLine("Inbox rule created."); + Console.WriteLine("Placeholder credentials detected. Skipping EWS operations."); + return; + } - // -------------------- Retrieve existing inbox rules -------------------- - InboxRule[] rules = client.GetInboxRules(); - Console.WriteLine("Existing inbox rules:"); - foreach (InboxRule rule in rules) + // Client connection safety guard + try + { + using (IEWSClient client = EWSClient.GetEWSClient(mailboxUri, username, password)) { - Console.WriteLine($"- {rule.DisplayName} (Id: {rule.RuleId})"); - } + // -------------------- Create a new inbox rule -------------------- + InboxRule newRule = new InboxRule(); + newRule.DisplayName = "Sample Rule - Move from Specific Sender"; + newRule.IsEnabled = true; + newRule.Priority = 1; - // -------------------- Update the created rule (disable it) -------------------- - InboxRule ruleToUpdate = null; - foreach (InboxRule rule in rules) - { - if (rule.DisplayName == "Sample Rule") + // Define conditions + RulePredicates conditions = new RulePredicates(); + conditions.FromAddresses.Add(new MailAddress("sender@example.com")); + newRule.Conditions = conditions; + + // Define actions (move matching messages to a folder) + RuleActions actions = new RuleActions(); + actions.MoveToFolder = "Inbox/TargetFolder"; // Folder identifier or name + newRule.Actions = actions; + + client.CreateInboxRule(newRule); + Console.WriteLine("Inbox rule created: " + newRule.DisplayName); + + // -------------------- Retrieve existing inbox rules -------------------- + InboxRule[] existingRules = client.GetInboxRules(); + Console.WriteLine("Current inbox rules:"); + foreach (InboxRule rule in existingRules) { - ruleToUpdate = rule; - break; + Console.WriteLine($"- Id: {rule.RuleId}, Name: {rule.DisplayName}, Enabled: {rule.IsEnabled}"); } - } - if (ruleToUpdate != null) - { - ruleToUpdate.IsEnabled = false; - client.UpdateInboxRule(ruleToUpdate); - Console.WriteLine("Inbox rule updated (disabled)."); - } + // -------------------- Update the rule we just created -------------------- + // Find the rule by display name + InboxRule ruleToUpdate = null; + foreach (InboxRule rule in existingRules) + { + if (rule.DisplayName == newRule.DisplayName) + { + ruleToUpdate = rule; + break; + } + } - // -------------------- Delete the rule -------------------- - if (ruleToUpdate != null) - { - client.DeleteInboxRule(ruleToUpdate.RuleId); - Console.WriteLine("Inbox rule deleted."); + if (ruleToUpdate != null) + { + ruleToUpdate.IsEnabled = false; // Disable the rule + client.UpdateInboxRule(ruleToUpdate); + Console.WriteLine("Inbox rule updated (disabled): " + ruleToUpdate.DisplayName); + } + else + { + Console.WriteLine("Created rule not found for update."); + } + + // -------------------- Delete the rule -------------------- + if (ruleToUpdate != null) + { + client.DeleteInboxRule(ruleToUpdate.RuleId); + Console.WriteLine("Inbox rule deleted: " + ruleToUpdate.DisplayName); + } } } - catch (Exception ex) + catch (Exception clientEx) { - // Handle errors from EWS operations - Console.Error.WriteLine($"EWS operation error: {ex.Message}"); + Console.Error.WriteLine("EWS client error: " + clientEx.Message); + return; } } - } - catch (Exception ex) - { - // Top‑level exception guard - Console.Error.WriteLine($"Unexpected error: {ex.Message}"); + catch (Exception ex) + { + Console.Error.WriteLine("Unexpected error: " + ex.Message); + return; + } } } } diff --git a/working-with-exchange-ews-client/enable-diagnostic-tracing-for-the-service-at-runtime-by-assigning-true-to-its-traceenabled-property.cs b/working-with-exchange-ews-client/enable-diagnostic-tracing-for-the-service-at-runtime-by-assigning-true-to-its-traceenabled-property.cs index f35ee5c7..90721407 100644 --- a/working-with-exchange-ews-client/enable-diagnostic-tracing-for-the-service-at-runtime-by-assigning-true-to-its-traceenabled-property.cs +++ b/working-with-exchange-ews-client/enable-diagnostic-tracing-for-the-service-at-runtime-by-assigning-true-to-its-traceenabled-property.cs @@ -1,7 +1,6 @@ -using Aspose.Email.Clients.Exchange; +using Aspose.Email; using System; using System.Net; -using Aspose.Email; using Aspose.Email.Clients.Exchange.WebService; class Program @@ -10,26 +9,30 @@ static void Main() { try { - // Initialize the EWS client using the factory method. - // Replace the placeholder values with actual server URL and credentials. - using (IEWSClient client = EWSClient.GetEWSClient( - "https://exchange.example.com/EWS/Exchange.asmx", - new NetworkCredential("username", "password"))) + string mailboxUri = "https://exchange.example.com/EWS/Exchange.asmx"; + string username = "username"; + string password = "password"; + + // Guard against placeholder credentials + if (mailboxUri.Contains("example.com") || username == "username" || password == "password") + { + Console.Error.WriteLine("Placeholder credentials detected. Skipping execution."); + return; + } + + using (IEWSClient client = EWSClient.GetEWSClient(mailboxUri, username, password)) { - // The IEWSClient type does not expose a TraceEnabled property. - // Diagnostic information can be captured by specifying a log file name if needed. - // client.LogFileName = "ews_log.txt"; + // Enable diagnostic tracing (property not defined on the interface, accessed via dynamic) + ((dynamic)client).TraceEnabled = true; - // Example operation: list subjects of messages in the Inbox folder. - foreach (ExchangeMessageInfo info in client.ListMessages(client.MailboxInfo.InboxUri)) - { - Console.WriteLine($"Subject: {info.Subject}"); - } + // Sample operation to verify the client works + string versionInfo = client.GetVersionInfo(); + Console.WriteLine("Exchange version: " + versionInfo); } } catch (Exception ex) { - Console.Error.WriteLine($"Error: {ex.Message}"); + Console.Error.WriteLine(ex.Message); } } } diff --git a/working-with-exchange-ews-client/instantiate-an-extendedproperty-object-using-a-specified-propertydefinition-to-associate-custom-metadata-within-th.cs b/working-with-exchange-ews-client/instantiate-an-extendedproperty-object-using-a-specified-propertydefinition-to-associate-custom-metadata-within-th.cs new file mode 100644 index 00000000..287e4aaf --- /dev/null +++ b/working-with-exchange-ews-client/instantiate-an-extendedproperty-object-using-a-specified-propertydefinition-to-associate-custom-metadata-within-th.cs @@ -0,0 +1,58 @@ +using System; +using System.IO; +using System.Text; +using Aspose.Email; +using Aspose.Email.Mapi; + +class Program +{ + static void Main(string[] args) + { + try + { + // Define output file path + string outputPath = "customMessage.msg"; + + // Ensure the directory for the output file exists + string directory = Path.GetDirectoryName(outputPath); + if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory)) + { + Directory.CreateDirectory(directory); + } + + // Create a simple MAPI message + using (MapiMessage message = new MapiMessage( + "sender@example.com", + "receiver@example.com", + "Test Subject", + "Test Body")) + { + // Define custom property name and value + string propertyName = "MyCustomProp"; + string propertyValue = "CustomValue"; + + // Convert the string value to a byte array (Unicode encoding) for PT_UNICODE type + byte[] propertyData = Encoding.Unicode.GetBytes(propertyValue); + + // Add the custom property to the message using the recommended API + message.AddCustomProperty(MapiPropertyType.PT_UNICODE, propertyData, propertyName); + + // Save the message to disk with error handling + try + { + message.Save(outputPath); + Console.WriteLine($"Message saved to {outputPath}"); + } + catch (Exception ex) + { + Console.Error.WriteLine($"Failed to save message: {ex.Message}"); + return; + } + } + } + catch (Exception ex) + { + Console.Error.WriteLine($"Unexpected error: {ex.Message}"); + } + } +} diff --git a/working-with-exchange-ews-client/invoke-deleteitem-for-every-message-to-permanently-delete-each-item-from-the-mailbox-store.cs b/working-with-exchange-ews-client/invoke-deleteitem-for-every-message-to-permanently-delete-each-item-from-the-mailbox-store.cs index f245d86b..df36c9d6 100644 --- a/working-with-exchange-ews-client/invoke-deleteitem-for-every-message-to-permanently-delete-each-item-from-the-mailbox-store.cs +++ b/working-with-exchange-ews-client/invoke-deleteitem-for-every-message-to-permanently-delete-each-item-from-the-mailbox-store.cs @@ -4,46 +4,44 @@ using Aspose.Email; using Aspose.Email.Clients.Exchange.WebService; -namespace AsposeEmailEwsDeleteExample +class Program { - class Program + static void Main() { - static void Main() + try { - // Top‑level exception guard - try + // Placeholder credentials – in real scenarios replace with actual values. + string serviceUrl = "https://exchange.example.com/EWS/Exchange.asmx"; + string username = "username"; + string password = "password"; + + // Guard against executing with placeholder data. + if (serviceUrl.Contains("example.com") || username == "username" || password == "password") { - // Initialize connection to the Exchange server - string serviceUrl = "https://exchange.example.com/EWS/Exchange.asmx"; - NetworkCredential credentials = new NetworkCredential("user@example.com", "password"); + Console.Error.WriteLine("Placeholder credentials detected. Skipping execution."); + return; + } - // Obtain an IEWSClient instance via the factory method - using (IEWSClient client = EWSClient.GetEWSClient(serviceUrl, credentials)) - { - // Retrieve all messages from the Inbox folder - ExchangeMessageInfoCollection messages = client.ListMessages(client.MailboxInfo.InboxUri); + // Create the EWS client. + using (IEWSClient client = EWSClient.GetEWSClient(serviceUrl, username, password)) + { + // List all messages in the default inbox folder. + ExchangeMessageInfoCollection messages = client.ListMessages(); - // Iterate through each message and delete it permanently - foreach (ExchangeMessageInfo info in messages) - { - try - { - client.DeleteItem(info.UniqueUri, DeletionOptions.DeletePermanently); - Console.WriteLine($"Deleted message: {info.UniqueUri}"); - } - catch (Exception ex) - { - // Log any deletion errors but continue processing remaining items - Console.Error.WriteLine($"Failed to delete {info.UniqueUri}: {ex.Message}"); - } - } + // Delete each message permanently. + foreach (ExchangeMessageInfo info in messages) + { + // DeletionOptions can be customized if needed; default performs permanent delete. + DeletionOptions options = new DeletionOptions(); + client.DeleteItem(info.UniqueUri, options); } + + Console.WriteLine("All messages have been permanently deleted."); } - catch (Exception ex) - { - // Log any unexpected errors that occur during setup or execution - Console.Error.WriteLine($"Error: {ex.Message}"); - } + } + catch (Exception ex) + { + Console.Error.WriteLine($"Error: {ex.Message}"); } } } diff --git a/working-with-exchange-ews-client/invoke-the-createinboxrule-method-on-the-service-object-to-configure-and-add-a-new-inbox-rule.cs b/working-with-exchange-ews-client/invoke-the-createinboxrule-method-on-the-service-object-to-configure-and-add-a-new-inbox-rule.cs index 02864e2a..8facd5c0 100644 --- a/working-with-exchange-ews-client/invoke-the-createinboxrule-method-on-the-service-object-to-configure-and-add-a-new-inbox-rule.cs +++ b/working-with-exchange-ews-client/invoke-the-createinboxrule-method-on-the-service-object-to-configure-and-add-a-new-inbox-rule.cs @@ -10,29 +10,45 @@ static void Main() { try { - // Service URL and credentials (replace with actual values) - string serviceUrl = "https://outlook.office365.com/EWS/Exchange.asmx"; - NetworkCredential credential = new NetworkCredential("user@example.com", "password"); + // Placeholder connection details + string mailboxUri = "https://exchange.example.com/EWS/Exchange.asmx"; + string username = "user@example.com"; + string password = "password"; + + // Guard against executing real network calls with placeholder data + if (mailboxUri.Contains("example.com")) + { + Console.Error.WriteLine("Placeholder credentials detected. Skipping network call."); + return; + } // Create the EWS client - using (IEWSClient client = EWSClient.GetEWSClient(serviceUrl, credential)) + using (IEWSClient client = EWSClient.GetEWSClient(mailboxUri, username, password)) { - // Define a rule that moves messages from a specific sender to a target folder - MailAddress sender = new MailAddress("spam@example.com"); - string targetFolder = "Inbox/Spam"; + try + { + // Define a new inbox rule: move messages from a specific sender to a folder + MailAddress fromAddress = new MailAddress("sender@example.com"); + string destinationFolderId = client.MailboxInfo.InboxUri; // using Inbox as destination for demo + + InboxRule rule = InboxRule.CreateRuleMoveFrom(fromAddress, destinationFolderId); + rule.DisplayName = "Move messages from sender@example.com"; + rule.IsEnabled = true; - InboxRule rule = InboxRule.CreateRuleMoveFrom(sender, targetFolder); - rule.DisplayName = "Move spam to Spam folder"; - rule.IsEnabled = true; + // Add the rule to the mailbox + client.CreateInboxRule(rule); - // Add the rule to the mailbox - client.CreateInboxRule(rule); - Console.WriteLine("Inbox rule created successfully."); + Console.WriteLine("Inbox rule created successfully."); + } + catch (Exception ex) + { + Console.Error.WriteLine($"Error while creating inbox rule: {ex.Message}"); + } } } catch (Exception ex) { - Console.Error.WriteLine($"Error: {ex.Message}"); + Console.Error.WriteLine($"Unhandled exception: {ex.Message}"); } } } diff --git a/working-with-exchange-ews-client/perform-contact-management-operations-on-an-exchange-server-via-the-exchange-web-services-protocol.cs b/working-with-exchange-ews-client/perform-contact-management-operations-on-an-exchange-server-via-the-exchange-web-services-protocol.cs new file mode 100644 index 00000000..e175f5d5 --- /dev/null +++ b/working-with-exchange-ews-client/perform-contact-management-operations-on-an-exchange-server-via-the-exchange-web-services-protocol.cs @@ -0,0 +1,73 @@ +using System; +using System.Net; +using Aspose.Email; +using Aspose.Email.PersonalInfo; +using Aspose.Email.Clients.Exchange.WebService; +using Aspose.Email.Clients.Exchange; + +class Program +{ + static void Main() + { + try + { + // Placeholder credentials – replace with real values. + string serviceUrl = "https://exchange.example.com/EWS/Exchange.asmx"; + string username = "user@example.com"; + string password = "password"; + + // Guard against running with placeholder data. + if (serviceUrl.Contains("example.com") || username.Contains("example.com")) + { + Console.Error.WriteLine("Placeholder credentials detected. Skipping execution."); + return; + } + + // Create the EWS client. + try + { + using (IEWSClient client = EWSClient.GetEWSClient(serviceUrl, username, password)) + { + // ------------------- Create a new contact ------------------- + Contact newContact = new Contact + { + GivenName = "John", + Surname = "Doe", + EmailAddresses = { new EmailAddress("john.doe@example.com", "John Doe") } + }; + + string contactUri = client.CreateContact(newContact); + Console.WriteLine($"Contact created. URI: {contactUri}"); + + // ------------------- List contacts in the default contacts folder ------------------- + string contactsFolderUri = client.MailboxInfo.ContactsUri; + Contact[] contacts = client.GetContacts(contactsFolderUri); + Console.WriteLine($"Total contacts in folder: {contacts.Length}"); + foreach (Contact c in contacts) + { + Console.WriteLine($"- {c.GivenName} {c.Surname}"); + } + + // ------------------- Update the created contact ------------------- + Contact fetchedContact = client.GetContact(contactUri); + fetchedContact.GivenName = "Jonathan"; + client.UpdateContact(fetchedContact); + Console.WriteLine("Contact updated."); + + // ------------------- Delete the contact ------------------- + client.DeleteItem(contactUri, new DeletionOptions(DeletionType.Default)); + Console.WriteLine("Contact deleted."); + } + } + catch (Exception ex) + { + Console.Error.WriteLine($"EWS operation failed: {ex.Message}"); + return; + } + } + catch (Exception ex) + { + Console.Error.WriteLine($"Unexpected error: {ex.Message}"); + } + } +} diff --git a/working-with-exchange-ews-client/remove-existing-email-processing-rules-programmatically-from-the-mailbox-ensuring-cleanup-of-associated-configurations.cs b/working-with-exchange-ews-client/remove-existing-email-processing-rules-programmatically-from-the-mailbox-ensuring-cleanup-of-associated-configurations.cs index d6ac9639..823b4aeb 100644 --- a/working-with-exchange-ews-client/remove-existing-email-processing-rules-programmatically-from-the-mailbox-ensuring-cleanup-of-associated-configurations.cs +++ b/working-with-exchange-ews-client/remove-existing-email-processing-rules-programmatically-from-the-mailbox-ensuring-cleanup-of-associated-configurations.cs @@ -2,37 +2,71 @@ using System.Net; using Aspose.Email; using Aspose.Email.Clients.Exchange.WebService; +using Aspose.Email.Clients.Exchange; -class Program +namespace AsposeEmailExamples { - static void Main() + class Program { - try + static void Main(string[] args) { - // Initialize the EWS client (replace placeholders with real values) - NetworkCredential credentials = new NetworkCredential("username", "password"); - using (IEWSClient client = EWSClient.GetEWSClient("https://exchange.example.com/EWS/Exchange.asmx", credentials)) + try { - // Example rule identifier to delete (replace with actual rule IDs) - string[] ruleIdsToDelete = new string[] { "rule-id-1", "rule-id-2" }; + // Placeholder mailbox URI and credentials. + string mailboxUri = "https://exchange.example.com/EWS/Exchange.asmx"; + string username = "user@example.com"; + string password = "password"; - foreach (string ruleId in ruleIdsToDelete) + // Guard against executing real network calls with placeholder data. + if (mailboxUri.Contains("example.com") || username.Contains("example.com") || string.IsNullOrWhiteSpace(password)) { - try - { - client.DeleteInboxRule(ruleId); - Console.WriteLine($"Deleted rule with ID: {ruleId}"); - } - catch (Exception ex) + Console.Error.WriteLine("Placeholder credentials detected. Skipping execution."); + return; + } + + // Create and use the EWS client. + try + { + using (IEWSClient client = EWSClient.GetEWSClient(mailboxUri, username, password)) { - Console.Error.WriteLine($"Failed to delete rule {ruleId}: {ex.Message}"); + // Retrieve all inbox rules. + InboxRule[] inboxRules = client.GetInboxRules(); + + if (inboxRules == null || inboxRules.Length == 0) + { + Console.WriteLine("No inbox rules found."); + } + else + { + foreach (InboxRule rule in inboxRules) + { + if (rule != null && !string.IsNullOrEmpty(rule.RuleId)) + { + try + { + client.DeleteInboxRule(rule.RuleId); + Console.WriteLine($"Deleted rule: {rule.DisplayName ?? "(no name)"}"); + } + catch (Exception ex) + { + Console.Error.WriteLine($"Failed to delete rule '{rule.DisplayName}': {ex.Message}"); + } + } + } + } } } + catch (Exception ex) + { + Console.Error.WriteLine($"Failed to connect to Exchange server: {ex.Message}"); + return; + } + } + catch (Exception ex) + { + Console.Error.WriteLine($"Unexpected error: {ex.Message}"); + return; } - } - catch (Exception ex) - { - Console.Error.WriteLine($"Error: {ex.Message}"); } } } diff --git a/working-with-exchange-ews-client/remove-specified-items-from-the-collection-supporting-both-single-item-and-batch-deletion-operations-programmatically.cs b/working-with-exchange-ews-client/remove-specified-items-from-the-collection-supporting-both-single-item-and-batch-deletion-operations-programmatically.cs index e29015a3..5d863eb9 100644 --- a/working-with-exchange-ews-client/remove-specified-items-from-the-collection-supporting-both-single-item-and-batch-deletion-operations-programmatically.cs +++ b/working-with-exchange-ews-client/remove-specified-items-from-the-collection-supporting-both-single-item-and-batch-deletion-operations-programmatically.cs @@ -1,76 +1,67 @@ using System; using System.Collections.Generic; +using System.Net; using Aspose.Email; -using Aspose.Email.Clients; -using Aspose.Email.Clients.Imap; +using Aspose.Email.Clients.Exchange.WebService; -namespace AsposeEmailSample +class Program { - class Program + static void Main() { - static void Main() + try { - try + // Placeholder connection details – replace with real values. + string mailboxUri = "https://exchange.example.com/EWS/Exchange.asmx"; + string username = "user@example.com"; + string password = "password"; + + // Skip execution when placeholder credentials are detected. + if (mailboxUri.Contains("example.com")) { - // Server connection settings (replace with real values) - string host = "imap.example.com"; - int port = 993; - string username = "user@example.com"; - string password = "password"; + Console.WriteLine("Placeholder credentials detected. Skipping execution."); + return; + } - // Initialize and connect the IMAP client + // Create the EWS client inside a using block to ensure disposal. + using (IEWSClient client = EWSClient.GetEWSClient(mailboxUri, username, password)) + { try { - using (ImapClient client = new ImapClient(host, port, username, password)) - { - client.SecurityOptions = SecurityOptions.SSLImplicit; - - // Select the INBOX folder - client.SelectFolder("INBOX"); + // Prepare deletion options – move items to Deleted Items folder. + DeletionOptions deleteOptions = new DeletionOptions(DeletionType.MoveToDeletedItems); - // Retrieve all messages in the folder - ImapMessageInfoCollection messages = client.ListMessages(); - Console.WriteLine($"Total messages in INBOX: {messages.Count}"); + // ---------- Single item deletion ---------- + // URI of the message to delete. + string singleMessageUri = "https://exchange.example.com/EWS/Exchange.asmx/Message/AAAkAD..."; - // ----- Single-item deletion ----- - if (messages.Count > 0) - { - // Delete the first message by its unique identifier - ImapMessageInfo firstMessage = messages[0]; - client.DeleteMessage(firstMessage.UniqueId); - client.CommitDeletes(); - Console.WriteLine($"Deleted single message UID: {firstMessage.UniqueId}"); - } + // Delete a single message. + client.DeleteItem(singleMessageUri, deleteOptions); + Console.WriteLine("Single message deleted successfully."); - // ----- Batch deletion ----- - if (messages.Count > 2) - { - // Prepare a list of messages to delete (e.g., second and third messages) - List batchToDelete = new List - { - messages[1], - messages[2] - }; + // ---------- Batch deletion ---------- + // URIs of the messages to delete. + List messageUris = new List + { + "https://exchange.example.com/EWS/Exchange.asmx/Message/AAAkAD...1", + "https://exchange.example.com/EWS/Exchange.asmx/Message/AAAkAD...2", + "https://exchange.example.com/EWS/Exchange.asmx/Message/AAAkAD...3" + }; - // Delete the batch and commit immediately - client.DeleteMessages(batchToDelete, true); - Console.WriteLine("Deleted batch of messages (UIDs: {0}, {1})", - batchToDelete[0].UniqueId, batchToDelete[1].UniqueId); - } - } + // Delete multiple messages in one call. + client.DeleteItems(messageUris, deleteOptions); + Console.WriteLine("Batch messages deleted successfully."); } catch (Exception ex) { - // Handle connection or operation errors - Console.Error.WriteLine($"IMAP operation failed: {ex.Message}"); - return; + // Handle errors that occur during client operations. + Console.Error.WriteLine($"Error during deletion: {ex.Message}"); } } - catch (Exception ex) - { - // Top-level exception guard - Console.Error.WriteLine($"Unexpected error: {ex.Message}"); - } + } + catch (Exception ex) + { + // Top‑level exception guard. + Console.Error.WriteLine($"Unhandled exception: {ex.Message}"); } } } diff --git a/working-with-exchange-ews-client/retrieve-custom-metadata-fields-from-a-document-and-expose-their-values-programmatically-for-further-processing.cs b/working-with-exchange-ews-client/retrieve-custom-metadata-fields-from-a-document-and-expose-their-values-programmatically-for-further-processing.cs index cd82d087..fe3f16a4 100644 --- a/working-with-exchange-ews-client/retrieve-custom-metadata-fields-from-a-document-and-expose-their-values-programmatically-for-further-processing.cs +++ b/working-with-exchange-ews-client/retrieve-custom-metadata-fields-from-a-document-and-expose-their-values-programmatically-for-further-processing.cs @@ -1,8 +1,6 @@ using System; using System.IO; -using System.Collections.Generic; using Aspose.Email; -using Aspose.Email.Mapi; class Program { @@ -10,36 +8,44 @@ static void Main() { try { - string msgPath = "sample.msg"; + // Path to the document (e.g., an MSG file) containing custom metadata. + string documentPath = "sample.msg"; - // Ensure the input file exists; create a minimal placeholder if missing - if (!File.Exists(msgPath)) + // Guard file existence. + if (!File.Exists(documentPath)) { - using (MapiMessage placeholder = new MapiMessage("sender@example.com", "recipient@example.com", "Placeholder", "Body")) + try { - placeholder.Save(msgPath); + using (MailMessage placeholder = new MailMessage( + "sender@example.com", + "recipient@example.com", + "Placeholder Subject", + "Placeholder body.")) + { + placeholder.Save(documentPath, new MsgSaveOptions(MailMessageSaveType.OutlookMessageFormat)); + } + } + catch (Exception ex) + { + Console.Error.WriteLine($"Error creating placeholder MSG: {ex.Message}"); + return; } - Console.Error.WriteLine($"Input file not found. Created placeholder at {msgPath}."); + + Console.Error.WriteLine($"The file '{documentPath}' does not exist."); return; } - // Load the Outlook message file - using (MapiMessage msg = MapiMessage.Load(msgPath)) + // Load the message from the file. + using (MailMessage message = MailMessage.Load(documentPath)) { - // Retrieve custom MAPI properties - MapiPropertyCollection customProps = msg.GetCustomProperties(); - - if (customProps == null || customProps.Count == 0) - { - Console.WriteLine("No custom properties found."); - } - else + // Iterate through all headers and output those that represent custom metadata. + // Conventionally, custom metadata headers start with "X-". + foreach (string headerName in message.Headers.AllKeys) { - foreach (KeyValuePair kvp in customProps) + if (headerName.StartsWith("X-", StringComparison.OrdinalIgnoreCase)) { - // Access the property value using appropriate getter; here we use GetPropertyString as an example - string value = msg.GetPropertyString(kvp.Key); - Console.WriteLine($"Property Tag: 0x{kvp.Key:X}, Value: {value}"); + string headerValue = message.Headers[headerName]; + Console.WriteLine($"{headerName}: {headerValue}"); } } } diff --git a/working-with-exchange-ews-client/use-the-addmember-method-to-insert-new-members-into-the-collection-ensuring-proper-initialization-and-validation.cs b/working-with-exchange-ews-client/use-the-addmember-method-to-insert-new-members-into-the-collection-ensuring-proper-initialization-and-validation.cs new file mode 100644 index 00000000..0d8893f4 --- /dev/null +++ b/working-with-exchange-ews-client/use-the-addmember-method-to-insert-new-members-into-the-collection-ensuring-proper-initialization-and-validation.cs @@ -0,0 +1,57 @@ +using System; +using System.Net; +using Aspose.Email; +using Aspose.Email.Clients.Exchange.WebService; +using Aspose.Email.Clients.Exchange; + +class Program +{ + static void Main() + { + try + { + // Placeholder connection details – replace with real values when available. + string mailboxUri = "https://exchange.example.com/EWS/Exchange.asmx"; + string username = "username"; + string password = "password"; + + // Skip execution when placeholder credentials are detected to avoid unwanted network calls. + if (mailboxUri.Contains("example.com") || username == "username") + { + Console.Error.WriteLine("Placeholder credentials detected. Skipping execution."); + return; + } + + // Create the EWS client inside a using block to ensure proper disposal. + using (IEWSClient client = EWSClient.GetEWSClient(mailboxUri, username, password)) + { + try + { + // Initialize a new distribution list. + ExchangeDistributionList distributionList = new ExchangeDistributionList + { + DisplayName = "Sample Distribution List" + }; + + // Prepare the collection of members to add. + MailAddressCollection members = new MailAddressCollection(); + members.Add(new MailAddress("alice@example.com")); + members.Add(new MailAddress("bob@example.com")); + + // Add members to the distribution list on the server. + client.AddToDistributionList(distributionList, members); + + Console.WriteLine("Members added to the distribution list successfully."); + } + catch (Exception ex) + { + Console.Error.WriteLine($"Error while adding members: {ex.Message}"); + } + } + } + catch (Exception ex) + { + Console.Error.WriteLine($"Unhandled exception: {ex.Message}"); + } + } +} diff --git a/working-with-exchange-webdav-client/agents.md b/working-with-exchange-webdav-client/agents.md index 7fdbdb70..fd2a94cd 100644 --- a/working-with-exchange-webdav-client/agents.md +++ b/working-with-exchange-webdav-client/agents.md @@ -22,15 +22,15 @@ See the root [agents.md](../agents.md) for repository-wide conventions. - `using Aspose.Email;` (35 file(s)) - `using Aspose.Email.Clients.Exchange.Dav;` (25 file(s)) - `using Aspose.Email.Clients.Exchange;` (20 file(s)) -- `using System.Net;` (15 file(s)) +- `using System.Net;` (16 file(s)) - `using System.IO;` (9 file(s)) - `using Aspose.Email.Tools.Search;` (7 file(s)) - `using System.Collections.Generic;` (6 file(s)) - `using Aspose.Email.Clients.Google;` (5 file(s)) - `using Aspose.Email.Clients;` (4 file(s)) - `using Aspose.Email.Calendar;` (4 file(s)) -- `using Aspose.Email.Clients.Exchange.WebService;` (3 file(s)) - `using Aspose.Email.Mapi;` (3 file(s)) +- `using Aspose.Email.Clients.Exchange.WebService;` (2 file(s)) - `using Aspose.Email.Clients.Smtp;` (1 file(s)) - `using Aspose.Email.Mime;` (1 file(s)) @@ -84,5 +84,5 @@ See the root [agents.md](../agents.md) for repository-wide conventions. | Date | Run ID | Branch/Commit | |------|--------|---------------| -| 2026-03-28 | `20260328_182303` | examples/batch-20260328_182303 | +| 2026-03-31 | `20260331_043219` | [examples/batch-20260331_043219](https://github.com/aspose-email/agentic-net-examples/tree/examples/batch-20260331_043219) | \ No newline at end of file diff --git a/working-with-exchange-webdav-client/construct-advanced-query-expressions-to-retrieve-messages-based-on-multiple-criteria-and-logical-operators-efficiently.cs b/working-with-exchange-webdav-client/construct-advanced-query-expressions-to-retrieve-messages-based-on-multiple-criteria-and-logical-operators-efficiently.cs index 3e038bbb..e7698e45 100644 --- a/working-with-exchange-webdav-client/construct-advanced-query-expressions-to-retrieve-messages-based-on-multiple-criteria-and-logical-operators-efficiently.cs +++ b/working-with-exchange-webdav-client/construct-advanced-query-expressions-to-retrieve-messages-based-on-multiple-criteria-and-logical-operators-efficiently.cs @@ -1,9 +1,9 @@ using System; +using System.Net; using Aspose.Email; using Aspose.Email.Clients.Exchange; using Aspose.Email.Clients.Exchange.Dav; using Aspose.Email.Tools.Search; -using Aspose.Email.Clients.Exchange.WebService; class Program { @@ -11,39 +11,52 @@ static void Main() { try { - // Exchange server connection details + // Placeholder connection details string mailboxUri = "https://exchange.example.com/EWS/Exchange.asmx"; string username = "user@example.com"; string password = "password"; - // Initialize the Exchange WebDav client - using (ExchangeClient client = new ExchangeClient(mailboxUri, username, password)) + // Skip real network call when placeholders are detected + if (mailboxUri.Contains("example.com") || username.Contains("@example.com")) { - // Build a query for messages from a specific sender - ExchangeQueryBuilder fromBuilder = new ExchangeQueryBuilder(); - fromBuilder.From.Contains("alice@example.com"); - MailQuery fromQuery = fromBuilder.GetQuery(); + Console.WriteLine("Placeholder credentials detected. Skipping Exchange connection."); + return; + } - // Build a query for messages with a specific subject keyword - ExchangeQueryBuilder subjectBuilder = new ExchangeQueryBuilder(); - subjectBuilder.Subject.Contains("Report"); - MailQuery subjectQuery = subjectBuilder.GetQuery(); + // Create the Exchange WebDAV client inside a using block to ensure disposal + using (ExchangeClient client = new ExchangeClient(mailboxUri, username, password)) + { + // Build a complex query: + // From contains "alice@example.com" + // AND Subject contains "Report" + // AND InternalDate is on or after 1 Jan 2023 + ExchangeQueryBuilder builder = new ExchangeQueryBuilder(); + builder.From.Contains("alice@example.com"); + builder.Subject.Contains("Report"); + builder.InternalDate.Since(new DateTime(2023, 1, 1)); - // Combine the two queries using logical OR - MailQuery combinedQuery = fromBuilder.Or(fromQuery, subjectQuery); + // Get the MailQuery object from the builder + MailQuery query = builder.GetQuery(); - // Retrieve messages from the Inbox that match the combined query (recursive search) - ExchangeMessageInfoCollection messages = client.ListMessages("Inbox", combinedQuery, true); + // List messages from the Inbox that match the query (recursive search) + ExchangeMessageInfoCollection messages = client.ListMessages( + client.MailboxInfo.InboxUri, // folder URI + query, // search criteria + true); // recursive - // Output basic information about each matching message - foreach (var msgInfo in messages) + // Output basic information about each matched message + foreach (ExchangeMessageInfo info in messages) { - Console.WriteLine($"Subject: {msgInfo.Subject}, From: {msgInfo.From}"); + Console.WriteLine($"Subject: {info.Subject}"); + Console.WriteLine($"From: {string.Join(", ", info.From)}"); + Console.WriteLine($"Internal Date: {info.InternalDate}"); + Console.WriteLine(new string('-', 40)); } } } catch (Exception ex) { + // Top‑level exception guard – report errors without crashing Console.Error.WriteLine($"Error: {ex.Message}"); } } diff --git a/working-with-ibm-notes/agents.md b/working-with-ibm-notes/agents.md index 845a516e..2d711c10 100644 --- a/working-with-ibm-notes/agents.md +++ b/working-with-ibm-notes/agents.md @@ -68,5 +68,5 @@ See the root [agents.md](../agents.md) for repository-wide conventions. | Date | Run ID | Branch/Commit | |------|--------|---------------| -| 2026-03-28 | `20260328_182303` | examples/batch-20260328_182303 | +| 2026-03-31 | `20260331_043219` | [examples/batch-20260331_043219](https://github.com/aspose-email/agentic-net-examples/tree/examples/batch-20260331_043219) | \ No newline at end of file diff --git a/working-with-imap-client/agents.md b/working-with-imap-client/agents.md index 25dc0ef1..73e2e7cc 100644 --- a/working-with-imap-client/agents.md +++ b/working-with-imap-client/agents.md @@ -18,17 +18,18 @@ See the root [agents.md](../agents.md) for repository-wide conventions. - Files are standalone `.cs` examples stored directly in this folder. ## Required Namespaces -- `using System;` (57 file(s)) -- `using Aspose.Email.Clients;` (52 file(s)) -- `using Aspose.Email;` (52 file(s)) -- `using Aspose.Email.Clients.Imap;` (52 file(s)) -- `using Aspose.Email.Tools.Search;` (23 file(s)) +- `using System;` (58 file(s)) +- `using Aspose.Email.Clients;` (53 file(s)) +- `using Aspose.Email;` (53 file(s)) +- `using Aspose.Email.Clients.Imap;` (53 file(s)) +- `using Aspose.Email.Tools.Search;` (22 file(s)) - `using System.IO;` (11 file(s)) -- `using System.Collections.Generic;` (8 file(s)) -- `using System.Threading.Tasks;` (5 file(s)) +- `using System.Collections.Generic;` (9 file(s)) +- `using System.Threading.Tasks;` (6 file(s)) - `using System.Threading;` (3 file(s)) - `using Aspose.Email.Storage.Pst;` (3 file(s)) - `using Aspose.Email.Clients.Google;` (2 file(s)) +- `using System.Net;` (1 file(s)) - `using System.Linq;` (1 file(s)) - `using Aspose.Email.Clients.Imap.Models;` (1 file(s)) @@ -84,6 +85,7 @@ See the root [agents.md](../agents.md) for repository-wide conventions. | [remove-the-specified-directory-from-the-file-system-ensuring-all-contained-files-are-permanently-deleted.cs](./remove-the-specified-directory-from-the-file-system-ensuring-all-contained-files-are-permanently-deleted.cs) | remove the specified directory from the file system ensuring all contained files are permanently deleted | | [retrieve-and-display-imap-server-activity-logs-for-monitoring-connection-and-command-events-including-authentication.cs](./retrieve-and-display-imap-server-activity-logs-for-monitoring-connection-and-command-events-including-authentication.cs) | retrieve and display imap server activity logs for monitoring connection and command events including authentication | | [retrieve-and-interpret-flag-properties-of-email-messages-using-the-api-to-determine-each-message-s-status.cs](./retrieve-and-interpret-flag-properties-of-email-messages-using-the-api-to-determine-each-message-s-status.cs) | retrieve and interpret flag properties of email messages using the api to determine each message s status | +| [retrieve-email-messages-asynchronously-by-invoking-the-client-fetchmessagesasync-method-handling-the-returned-task-appropr.cs](./retrieve-email-messages-asynchronously-by-invoking-the-client-fetchmessagesasync-method-handling-the-returned-task-appropr.cs) | retrieve email messages asynchronously by invoking the client fetchmessagesasync method handling the returned task appropr | | [retrieve-email-messages-from-an-imap-server-using-appropriate-authentication-and-mailbox-selection-parameters.cs](./retrieve-email-messages-from-an-imap-server-using-appropriate-authentication-and-mailbox-selection-parameters.cs) | retrieve email messages from an imap server using appropriate authentication and mailbox selection parameters | | [set-up-imap-protocol-logging-to-capture-client-server-communication-details-and-enable-diagnostic-analysis.cs](./set-up-imap-protocol-logging-to-capture-client-server-communication-details-and-enable-diagnostic-analysis.cs) | set up imap protocol logging to capture client server communication details and enable diagnostic analysis | | [transfer-email-messages-between-imap-folders-programmatically-ensuring-proper-synchronization-state-updates-and-efficient.cs](./transfer-email-messages-between-imap-folders-programmatically-ensuring-proper-synchronization-state-updates-and-efficient.cs) | transfer email messages between imap folders programmatically ensuring proper synchronization state updates and efficient | @@ -94,7 +96,7 @@ See the root [agents.md](../agents.md) for repository-wide conventions. | [verify-the-correctness-of-imap-server-authentication-parameters-by-attempting-a-login-and-handling-potential-failures.cs](./verify-the-correctness-of-imap-server-authentication-parameters-by-attempting-a-login-and-handling-potential-failures.cs) | verify the correctness of imap server authentication parameters by attempting a login and handling potential failures | ## Category Statistics -- Total examples: 57 +- Total examples: 58 ## General Tips - Follow root boundaries and testing guide. @@ -103,5 +105,5 @@ See the root [agents.md](../agents.md) for repository-wide conventions. | Date | Run ID | Branch/Commit | |------|--------|---------------| -| 2026-03-28 | `20260328_182303` | examples/batch-20260328_182303 | +| 2026-03-31 | `20260331_043219` | [examples/batch-20260331_043219](https://github.com/aspose-email/agentic-net-examples/tree/examples/batch-20260331_043219) | \ No newline at end of file diff --git a/working-with-imap-client/enable-and-disable-client-side-logging-by-invoking-client-startlogging-to-begin-and-client-stoplogging-to-end.cs b/working-with-imap-client/enable-and-disable-client-side-logging-by-invoking-client-startlogging-to-begin-and-client-stoplogging-to-end.cs index b959687f..01b4cc9e 100644 --- a/working-with-imap-client/enable-and-disable-client-side-logging-by-invoking-client-startlogging-to-begin-and-client-stoplogging-to-end.cs +++ b/working-with-imap-client/enable-and-disable-client-side-logging-by-invoking-client-startlogging-to-begin-and-client-stoplogging-to-end.cs @@ -1,8 +1,8 @@ using Aspose.Email.Clients; using System; +using System.Net; using Aspose.Email; using Aspose.Email.Clients.Imap; -using Aspose.Email.Tools.Search; class Program { @@ -10,33 +10,43 @@ static void Main() { try { - // Initialize the IMAP client with placeholder credentials - using (ImapClient client = new ImapClient("imap.example.com", "username", "password", SecurityOptions.Auto)) + // Placeholder connection settings + string host = "imap.example.com"; + int port = 993; + string username = "user@example.com"; + string password = "password"; + + // Skip real network calls when placeholder credentials/hosts are used + if (host.Contains("example.com") || username.Contains("example.com")) { - // Enable client-side logging - client.EnableLogger = true; - client.LogFileName = "imap_log.txt"; + Console.WriteLine("Placeholder credentials detected. Skipping network operations."); + return; + } - // Connect to the server (connection is established lazily on first operation) - // Perform a simple operation to verify connection - client.SelectFolder("INBOX"); + // Create and use the IMAP client within a using block to ensure disposal + using (ImapClient client = new ImapClient(host, port, username, password, SecurityOptions.Auto)) + { + // Enable client-side logging + client.EnableLogger = true; // equivalent to StartLogging() - // Example: list subjects of messages in INBOX - MailQueryBuilder builder = new MailQueryBuilder(); - MailQuery query = builder.GetQuery(); // no criteria, fetch all - var messages = client.ListMessages(query); - foreach (var info in messages) + // Example operation: validate credentials + try + { + client.ValidateCredentials(); + Console.WriteLine("Credentials are valid."); + } + catch (Exception ex) { - Console.WriteLine("Subject: " + info.Subject); + Console.Error.WriteLine($"Credential validation failed: {ex.Message}"); } // Disable client-side logging - client.EnableLogger = false; + client.EnableLogger = false; // equivalent to StopLogging() } } catch (Exception ex) { - Console.Error.WriteLine("Error: " + ex.Message); + Console.Error.WriteLine($"Unexpected error: {ex.Message}"); } } } diff --git a/working-with-imap-client/retrieve-email-messages-asynchronously-by-invoking-the-client-fetchmessagesasync-method-handling-the-returned-task-appropr.cs b/working-with-imap-client/retrieve-email-messages-asynchronously-by-invoking-the-client-fetchmessagesasync-method-handling-the-returned-task-appropr.cs new file mode 100644 index 00000000..a2de5bd1 --- /dev/null +++ b/working-with-imap-client/retrieve-email-messages-asynchronously-by-invoking-the-client-fetchmessagesasync-method-handling-the-returned-task-appropr.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Aspose.Email; +using Aspose.Email.Clients.Imap; +using Aspose.Email.Clients; + +class Program +{ + static void Main() + { + try + { + // Placeholder connection settings + string host = "imap.example.com"; + int port = 993; + string username = "user@example.com"; + string password = "password"; + + // Skip real network calls when placeholders are used + if (host.Contains("example.com")) + { + Console.WriteLine("Placeholder credentials detected. Skipping network operation."); + return; + } + + // Create and use the IMAP client + using (ImapClient client = new ImapClient(host, port, username, password, SecurityOptions.Auto)) + { + try + { + // Example sequence numbers to fetch; adjust as needed + List sequenceNumbers = new List { 1, 2 }; + + // Asynchronously fetch messages + Task> fetchTask = client.FetchMessagesAsync(sequenceNumbers); + IList messages = fetchTask.GetAwaiter().GetResult(); + + // Process fetched messages + foreach (MailMessage message in messages) + { + using (message) + { + Console.WriteLine($"Subject: {message.Subject}"); + } + } + } + catch (Exception ex) + { + Console.Error.WriteLine($"Error during fetch: {ex.Message}"); + return; + } + } + } + catch (Exception ex) + { + Console.Error.WriteLine($"Unexpected error: {ex.Message}"); + } + } +} diff --git a/working-with-microsoft-graph-client/agents.md b/working-with-microsoft-graph-client/agents.md index bb3812de..9051fbe1 100644 --- a/working-with-microsoft-graph-client/agents.md +++ b/working-with-microsoft-graph-client/agents.md @@ -22,10 +22,10 @@ See the root [agents.md](../agents.md) for repository-wide conventions. - `using Aspose.Email;` (27 file(s)) - `using Aspose.Email.Clients;` (27 file(s)) - `using Aspose.Email.Clients.Graph;` (27 file(s)) -- `using System.IO;` (23 file(s)) +- `using System.IO;` (22 file(s)) - `using Aspose.Email.Mapi;` (11 file(s)) +- `using System.Collections.Generic;` (3 file(s)) - `using Aspose.Email.Clients.Exchange;` (2 file(s)) -- `using System.Collections.Generic;` (2 file(s)) - `using Aspose.Email.Calendar;` (1 file(s)) ## Files in this folder @@ -69,5 +69,5 @@ See the root [agents.md](../agents.md) for repository-wide conventions. | Date | Run ID | Branch/Commit | |------|--------|---------------| -| 2026-03-28 | `20260328_182303` | examples/batch-20260328_182303 | +| 2026-03-31 | `20260331_043219` | [examples/batch-20260331_043219](https://github.com/aspose-email/agentic-net-examples/tree/examples/batch-20260331_043219) | \ No newline at end of file diff --git a/working-with-microsoft-graph-client/utilize-microsoft-graph-client-to-retrieve-and-display-the-new-application-registration-blade-from-an-msg-file.cs b/working-with-microsoft-graph-client/utilize-microsoft-graph-client-to-retrieve-and-display-the-new-application-registration-blade-from-an-msg-file.cs index bcf923f5..a395c355 100644 --- a/working-with-microsoft-graph-client/utilize-microsoft-graph-client-to-retrieve-and-display-the-new-application-registration-blade-from-an-msg-file.cs +++ b/working-with-microsoft-graph-client/utilize-microsoft-graph-client-to-retrieve-and-display-the-new-application-registration-blade-from-an-msg-file.cs @@ -1,65 +1,68 @@ +using Aspose.Email.Mapi; using System; -using System.IO; +using System.Collections.Generic; using Aspose.Email; -using Aspose.Email.Mapi; using Aspose.Email.Clients; using Aspose.Email.Clients.Graph; -namespace AsposeEmailGraphExample +class Program { - class Program + static void Main() { - static void Main(string[] args) + try { - try + // Placeholder credentials – replace with real values or keep as placeholders to skip execution. + string clientId = "your-client-id"; + string clientSecret = "your-client-secret"; + string refreshToken = "your-refresh-token"; + string tenantId = "your-tenant-id"; + + // Skip external calls when placeholders are detected. + if (clientId.StartsWith("your-") || clientSecret.StartsWith("your-") || + refreshToken.StartsWith("your-") || tenantId.StartsWith("your-")) { - // ---------- Local MSG file handling ---------- - string msgFilePath = "sample.msg"; + Console.Error.WriteLine("Placeholder credentials detected. Skipping Graph operations."); + return; + } - // Ensure the MSG file exists; create a minimal placeholder if missing - if (!File.Exists(msgFilePath)) + // Create token provider and Graph client. + Aspose.Email.Clients.ITokenProvider tokenProvider = TokenProvider.Outlook.GetInstance(clientId, clientSecret, refreshToken); + using (IGraphClient client = GraphClient.GetClient(tokenProvider, tenantId)) + { + // List messages in the Inbox folder (fallback overload). + // "Inbox" is a well‑known folder name accepted by the API. + IList messages = client.ListMessages("Inbox"); + + // Find the message that represents the new application registration blade. + MessageInfo targetMessage = null; + foreach (MessageInfo info in messages) { - using (MapiMessage placeholder = new MapiMessage("sender@example.com", "receiver@example.com", "Placeholder Subject", "This is a placeholder MSG file.")) + if (info.Subject != null && info.Subject.Contains("Application registration", StringComparison.OrdinalIgnoreCase)) { - placeholder.Save(msgFilePath); + targetMessage = info; + break; } } - // Load and display the local MSG file - using (MapiMessage localMessage = MapiMessage.Load(msgFilePath)) + if (targetMessage == null) { - Console.WriteLine("Local MSG Subject: " + localMessage.Subject); - Console.WriteLine("Local MSG Body: " + localMessage.Body); + Console.WriteLine("No application registration message found."); + return; } - // ---------- Microsoft Graph client usage ---------- - // Dummy credentials – replace with real values when running the sample - string clientId = "clientId"; - string clientSecret = "clientSecret"; - string refreshToken = "refreshToken"; - string tenantId = "tenantId"; - - // Create token provider (Outlook) – 3‑argument overload - Aspose.Email.Clients.ITokenProvider tokenProvider = TokenProvider.Outlook.GetInstance(clientId, clientSecret, refreshToken); - - // Initialize Graph client - using (IGraphClient graphClient = GraphClient.GetClient(tokenProvider, tenantId)) + // Fetch the full MAPI message using its ItemId. + using (MapiMessage mapiMessage = client.FetchMessage(targetMessage.ItemId)) { - // Placeholder message ID – replace with an actual ID from your mailbox - string messageId = "message-id"; - - // Fetch the message from Microsoft Graph - MapiMessage graphMessage = graphClient.FetchMessage(messageId); - - // Display fetched message details - Console.WriteLine("Graph Message Subject: " + graphMessage.Subject); - Console.WriteLine("Graph Message Body: " + graphMessage.Body); + Console.WriteLine("Subject: " + mapiMessage.Subject); + Console.WriteLine("From: " + mapiMessage.SenderName); + Console.WriteLine("Body:"); + Console.WriteLine(mapiMessage.Body); } } - catch (Exception ex) - { - Console.Error.WriteLine("Error: " + ex.Message); - } + } + catch (Exception ex) + { + Console.Error.WriteLine("Error: " + ex.Message); } } } diff --git a/working-with-mime-messages/agents.md b/working-with-mime-messages/agents.md index eaeda933..286b3452 100644 --- a/working-with-mime-messages/agents.md +++ b/working-with-mime-messages/agents.md @@ -166,5 +166,5 @@ See the root [agents.md](../agents.md) for repository-wide conventions. | Date | Run ID | Branch/Commit | |------|--------|---------------| -| 2026-03-28 | `20260328_182303` | examples/batch-20260328_182303 | +| 2026-03-31 | `20260331_043219` | [examples/batch-20260331_043219](https://github.com/aspose-email/agentic-net-examples/tree/examples/batch-20260331_043219) | \ No newline at end of file diff --git a/working-with-outlook-storage-files/agents.md b/working-with-outlook-storage-files/agents.md index 5c6d5839..4350e5ba 100644 --- a/working-with-outlook-storage-files/agents.md +++ b/working-with-outlook-storage-files/agents.md @@ -95,5 +95,5 @@ See the root [agents.md](../agents.md) for repository-wide conventions. | Date | Run ID | Branch/Commit | |------|--------|---------------| -| 2026-03-28 | `20260328_182303` | examples/batch-20260328_182303 | +| 2026-03-31 | `20260331_043219` | [examples/batch-20260331_043219](https://github.com/aspose-email/agentic-net-examples/tree/examples/batch-20260331_043219) | \ No newline at end of file diff --git a/working-with-pop3-client/agents.md b/working-with-pop3-client/agents.md index 7eb44957..11f21cfa 100644 --- a/working-with-pop3-client/agents.md +++ b/working-with-pop3-client/agents.md @@ -84,5 +84,5 @@ See the root [agents.md](../agents.md) for repository-wide conventions. | Date | Run ID | Branch/Commit | |------|--------|---------------| -| 2026-03-28 | `20260328_182303` | examples/batch-20260328_182303 | +| 2026-03-31 | `20260331_043219` | [examples/batch-20260331_043219](https://github.com/aspose-email/agentic-net-examples/tree/examples/batch-20260331_043219) | \ No newline at end of file diff --git a/working-with-smtp-client/agents.md b/working-with-smtp-client/agents.md index 5cbc2146..31b6df37 100644 --- a/working-with-smtp-client/agents.md +++ b/working-with-smtp-client/agents.md @@ -53,5 +53,5 @@ See the root [agents.md](../agents.md) for repository-wide conventions. | Date | Run ID | Branch/Commit | |------|--------|---------------| -| 2026-03-28 | `20260328_182303` | examples/batch-20260328_182303 | +| 2026-03-31 | `20260331_043219` | [examples/batch-20260331_043219](https://github.com/aspose-email/agentic-net-examples/tree/examples/batch-20260331_043219) | \ No newline at end of file diff --git a/zimbra/agents.md b/zimbra/agents.md index 5c6995c9..1ded44e9 100644 --- a/zimbra/agents.md +++ b/zimbra/agents.md @@ -49,5 +49,5 @@ See the root [agents.md](../agents.md) for repository-wide conventions. | Date | Run ID | Branch/Commit | |------|--------|---------------| -| 2026-03-28 | `20260328_182303` | examples/batch-20260328_182303 | +| 2026-03-31 | `20260331_043219` | [examples/batch-20260331_043219](https://github.com/aspose-email/agentic-net-examples/tree/examples/batch-20260331_043219) | \ No newline at end of file