通过 Aspose.Email Graph 客户端管理 Outlook 项目

管理日历事件

Aspose.Email 提供用于访问、管理和交互日历事件的 API。为此,它在以下位置提供了相应的方法: IGraphClient 接口:

  • ListCalendars() - 检索日历信息集合。
  • ListCalendarItems(string id) - 检索与指定日历 ID 关联的日历项集合。
  • FetchCalendarItem(string id) - 根据提供的 ID 检索特定日历项。
  • CreateCalendarItem(string calId, MapiCalendar mapiCalendar) - 在指定的日历中创建新日历项。
  • UpdateCalendarItem(MapiCalendar mapiCalendar) - 更新现有日历项。
  • UpdateCalendarItem(MapiCalendar mapiCalendar, UpdateSettings updateSettings) - 使用指定的更新设置更新现有日历项。

以下代码示例演示了如何使用 Aspose.Email 提供的方法在 Microsoft Graph API 客户端中与日历事件交互:


// List Calendars
CalendarInfoCollection calendars = graphClient.ListCalendars();

// List Calendar Items
MapiCalendarCollection calendarItems = graphClient.ListCalendarItems("calendarId");

// Fetch Calendar Item
MapiCalendar calendarItem = graphClient.FetchCalendarItem("calendarItemId");

// Create Calendar Item
MapiCalendar newCalendarItem = new MapiCalendar(
    location: "Conference Room",
    summary: "Team Meeting",
    description: "Discuss project status and updates.",
    startDate: startDate,
    endDate: endDate
);

MapiCalendar createdCalendarItem = graphClient.CreateCalendarItem("calendarId", newCalendarItem);

// Update Calendar Item
createdCalendarItem.Location = "Zoom Meeting";
MapiCalendar updatedCalendarItem = graphClient.UpdateCalendarItem(createdCalendarItem);

管理邮件类别

要使用 Aspose.Email for .NET 通过 MS Graph 管理类别,请使用以下方法并尝试以下代码示例:

// create a custom category with Orange color
var category = client.CreateCategory("My custom category", CategoryPreset.Preset1);

// fetch a category
var fetchedCategory = client.FetchCategory(category.Id);

// update category (change color to brown)
fetchedCategory.Preset = CategoryPreset.Preset2;
var updatedCategory = client.UpdateCategory(fetchedCategory);

// list available categories
var categories = client.ListCategories();

foreach (var cat in categories)
{
    Console.WriteLine(cat.DisplayName);
}

// delete a category
client.Delete(fetchedCategory.Id);

管理联系人

Aspose.Email 提供用于访问、管理和交互联系人项的 API。为此,它在以下位置提供了相应的方法: IGraphClient 接口:

  • ListContacts(string id) - 检索与指定文件夹 ID 关联的 MAPI 联系人集合。
  • FetchContact(string id) - 根据提供的项目 ID 检索特定联系人。
  • CreateContact(string folderId, MapiContact contact) - 在指定文件夹中创建新联系人。
  • UpdateContact(MapiContact contact) - 更新现有联系人。

以下代码示例演示了如何使用 Aspose.Email 提供的方法在 Microsoft Graph API 客户端中与联系人交互:

// List Contacts
MapiContactCollection contacts = graphClient.ListContacts("contactFolderId");

// Fetch Contact
MapiContact contact = graphClient.FetchContact("contactId");

// Create Contact
MapiContact newContact = new MapiContact("Jane Smith", "jane.smith@example.com", "XYZ Corporation", "777-888-999");

MapiContact createdContact = graphClient.CreateContact("contactFolderId", newContact);

// Update Contact
createdContact.Telephones.PrimaryTelephoneNumber = "888-888-999";

MapiContact updatedContact = graphClient.UpdateContact(createdContact);

管理覆盖

要使用 Aspose.Email for .NET 通过 MS Graph 管理覆盖,请使用以下方法:

// Create an user's override
var userOverride = client.CreateOrUpdateOverride
    (new MailAddress("JohnBrown@someorg.com", "JohnBrown"), ClassificationType.Focused);

// list the overrides
var overrides = client.ListOverrides();

// update override
userOverride.Sender.DisplayName = "John Brown";
var updatedOverride = client.UpdateOverride(userOverride);

// delete override
client.Delete(updatedOverride.Id);

管理收件箱规则

要使用 Aspose.Email for .NET 通过 MS Graph 管理规则,请使用以下方法:

// Create a rule
var rule = PrepareRule("user@someorg.com", "User");
var createdRule = client.CreateRule(rule);

// List all rules defined for Inbox
var rules = client.ListRules();

// Fetch a rule
var fetchedRule = client.FetchRule(createdRule.RuleId);

// Update a rule
fetchedRule.DisplayName = "Renamed rule";
fetchedRule.IsEnabled = false;
var updatedRule = client.UpdateRule(createdRule);

// Delete a rule
client.Delete(updatedRule.RuleId);
InboxRule PrepareRule(string email, string displayName)
{
    var rule = new InboxRule()
    {
        DisplayName = "My rule",
        Priority = 1,
        IsEnabled = true,
        Conditions = new RulePredicates(),
        Actions = new RuleActions()
    };

    rule.Conditions.ContainsSenderStrings = new StringCollection { displayName };
    rule.Actions.ForwardToRecipients = new MailAddressCollection
        { new MailAddress(email, displayName, true) };
    rule.Actions.StopProcessingRules = true;

    return rule;
}

管理 OneNote 笔记本

要使用 Aspose.Email for .NET 通过 MS Graph 管理笔记本,请使用以下方法:

// create a OneNote notebook
var newNotebook = new Notebook()
{
    DisplayName = "My Notebook"
};
var createdNotebook = client.CreateNotebook(newNotebook);

// fetch a notebook
var fetchedNotebook = client.FetchNotebook(createdNotebook.Id);

// list the notebooks
var notebooks = client.ListNotebooks();

在 Microsoft Graph 中管理任务

Aspose.Email 为开发者提供 API,通过以下方法访问、管理和交互用户的任务和任务列表 IGraphClient 接口:

下面的代码示例演示了如何管理任务列表:

// List Task Lists
var taskLists = graphClient.ListTaskLists();

foreach (var tList in taskLists)
{
    Console.WriteLine($"Task List: {tList.DisplayName}");
}

// Get Task List
var taskList = graphClient.GetTaskList("taskListId");

// Delete Task List
graphClient.DeleteTaskList("taskListId");

下面的代码示例演示了如何管理任务:

// List Tasks in a Task List
MapiTaskCollection tasks = graphClient.ListTasks("taskListId");

// Fetch Task
MapiTask task = graphClient.FetchTask("taskId");

// Create Task
var newTask = new MapiTask
{
    Subject = "New Task",
    DueDate = new DateTime(2023, 12, 31),
    Status = MapiTaskStatus.NotStarted
};

MapiTask createdTask = graphClient.CreateTask(newTask, "taskListUri");

// Update Task
createdTask.Subject = "Updated Task Subject";
MapiTask updatedTask = graphClient.UpdateTask(createdTask);

// Update Task with UpdateSettings
var updateSettings = new UpdateSettings { SkipAttachments  = true };
MapiTask updatedTaskWithSettings = graphClient.UpdateTask(createdTask, updateSettings);