使用 Python 从特定日期保存 Outlook 附件
Save Outlook attachment from a specific date using Python
我想知道如何将日期添加到此代码以保存来自 Outlook 的电子邮件附件文件:例如,我想保存在 20/04/2020 和 01/01 之间找到的文件/2020。请问你有什么想法吗?
outputDir = r"C:\Users\CMhalla\Desktop\attachment"
i=0
for m in messages:
if m.SenderEmailAddress == 'info@outlook.com':
body_content=m.Body
for attachment in m.Attachments:
i=i+1
attachment.SaveAsFile(os.path.join(outputDir,attachment.FileName + str(i)+'.xlsx'))
Outlook 对象模型提供 Items
class 的 Find/FindNext and Restrict 方法来获取符合您条件的项目。
- How To: Use Find and FindNext methods to retrieve Outlook mail items from a folder (C#, VB.NET)
- How To: Use Restrict method to retrieve Outlook mail items from a folder
您可能还会发现 How To: Retrieve Outlook calendar items using Find and FindNext methods 文章在使用类似搜索条件时很有帮助。
换行
for m in messages:
到(从我的头顶):
for m in messages.Restrict("([ReceivedTime] <= '04/20/2020') AND ([ReceivedTime] >= '01/01/2020') AND (SenderEmailAddress = 'info@outlook.com')"):
我想知道如何将日期添加到此代码以保存来自 Outlook 的电子邮件附件文件:例如,我想保存在 20/04/2020 和 01/01 之间找到的文件/2020。请问你有什么想法吗?
outputDir = r"C:\Users\CMhalla\Desktop\attachment"
i=0
for m in messages:
if m.SenderEmailAddress == 'info@outlook.com':
body_content=m.Body
for attachment in m.Attachments:
i=i+1
attachment.SaveAsFile(os.path.join(outputDir,attachment.FileName + str(i)+'.xlsx'))
Outlook 对象模型提供 Items
class 的 Find/FindNext and Restrict 方法来获取符合您条件的项目。
- How To: Use Find and FindNext methods to retrieve Outlook mail items from a folder (C#, VB.NET)
- How To: Use Restrict method to retrieve Outlook mail items from a folder
您可能还会发现 How To: Retrieve Outlook calendar items using Find and FindNext methods 文章在使用类似搜索条件时很有帮助。
换行
for m in messages:
到(从我的头顶):
for m in messages.Restrict("([ReceivedTime] <= '04/20/2020') AND ([ReceivedTime] >= '01/01/2020') AND (SenderEmailAddress = 'info@outlook.com')"):