我正在使用win32com 模块访问 Outlook 。
我想掌握任务和标记的邮件 - Outlook 有很多不同的名称,并将它们视为不同类型的“对象”。但是,我想获取按任务/待办事项列表(Outlook 2010)时出现的任务主题列表和截止日期。
@utapyngo 提出了一个非常有用的 C# 代码示例——但我真的需要一些帮助来将它翻译成 python。
Outlook.NameSpace ns = null;
Outlook.MAPIFolder todoFolder = null;
Outlook.Items todoFolderItems = null;
Outlook.TaskItem task = null;
Outlook.ContactItem contact = null;
Outlook.MailItem email = null;
string todoString = string.Empty;
try
{
ns = OutlookApp.Session;
todoFolder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderToDo);
todoFolderItems = todoFolder.Items;
for (int i = 1; i <= todoFolderItems.Count; i++)
{
object outlookItem = todoFolderItems[i];
if (outlookItem is Outlook.MailItem)
{
email = outlookItem as Outlook.MailItem;
todoString += String.Format("Email: {0} Due:{1}{2}",
email.Subject, email.TaskDueDate, Environment.NewLine);
}
else if (outlookItem is Outlook.ContactItem)
{
contact = outlookItem as Outlook.ContactItem;
todoString += String.Format("Contact: {0} Due:{1}{2}",
contact.FullName, contact.TaskDueDate, Environment.NewLine);
}
else if (outlookItem is Outlook.TaskItem)
{
task = outlookItem as Outlook.TaskItem;
todoString += String.Format("Task: {0} Due: {1}{2}",
task.Subject, task.DueDate, Environment.NewLine);
}
else
MessageBox.Show("Unknown Item type");
Marshal.ReleaseComObject(outlookItem);
}
MessageBox.Show(todoString);
}
finally
{
if (todoFolderItems != null)
Marshal.ReleaseComObject(todoFolderItems);
if (todoFolder != null)
Marshal.ReleaseComObject(todoFolder);
if (ns != null)
Marshal.ReleaseComObject(ns);
}