使用 Microsoft Outlook 2010 中的 Python 写入 csv

Write to a csv using Python from Microsoft Outlook 2010

我每周收到大约 60 封电子邮件,我必须手动将数据输入到 csv 文件中。我使用 Microsoft Outlook 2010,收件箱中有一个名为 'Market Emails' 的子文件夹。在这个子文件夹中,我有电子邮件,其中包括所有者姓名、公司名称和我需要写入 csv 的电子邮件。

我正尝试在 Python 中执行此操作,但我不确定是否能够执行此操作。感谢您提供的任何帮助!

这是一个相当广泛的问题,但是是的,这是可能的,使用 .NET COM 互操作

Whosebug post here 讨论了类似的内容,您可以使用它从收到的电子邮件中获取详细信息。

上面的代码post:

import win32com.client
import pythoncom
import re

class Handler_Class(object):
    def OnNewMailEx(self, receivedItemsIDs):
        # RecrivedItemIDs is a collection of mail IDs separated by a ",".
        # You know, sometimes more than 1 mail is received at the same moment.
        for ID in receivedItemsIDs.split(","):
            mail = outlook.Session.GetItemFromID(ID)
            subject = mail.Subject
            try:
                # Taking all the "BLAHBLAH" which is enclosed by two "%". 
                command = re.search(r"%(.*?)%", subject).group(1)

                print command # Or whatever code you wish to execute.
            except:
                pass


outlook = win32com.client.DispatchWithEvents("Outlook.Application", Handler_Class)

#and then an infinit loop that waits from events.
pythoncom.PumpMessages() 

Excel

然后您将通过相当广泛的教程 here.

继续使用 excel 的互操作