如何使用 python 在 outlook 中设置时间限制?
How to make a time restriction in outlook using python?
我正在制作一个程序:
- 打开 outlook
- 按主题查找电子邮件
- 从电子邮件中提取一些日期(代码和编号)
- 将这些数据填入excel文件中。
标准电子邮件如下所示:
Subject: Test1
Hi,
You got a new answer from user Alex.
Code: alex123fj
Number1: 0611111111
Number2: 1020
Number3: 3032
我在这个过程中遇到了2个主要问题。
首先,我不知道如何在 outlook 中对电子邮件进行时间限制。例如,如果我只想阅读昨天的电子邮件。
其次,我保存在列表中的电子邮件中的所有代码和数字。但是每个项目都从这个 ["alex123fj"]
得到这个 ["alex123fj/r"]
我将不胜感激任何帮助或建议,这是我在 Python 中的第一个程序。
这是我的代码:
import win32com.client
import re
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.Folders('myemail@....').Folders('Inbox')
messages = inbox.Items
def get_code(messages):
codes_lijst = []
for message in messages:
subject = message.subject
if subject == "Test1":
body = message.body
matches = re.finditer("Code:\s(.*)$", body, re.MULTILINE)
for match in matches:
codes_lijst.append(match.group(1))
return codes_lijst
def get_number(messages):
numbers_lijst = []
for message in messages:
subject = message.subject
if subject == "Test1":
body = message.body
matches = re.finditer("Number:\s(.*)$", body, re.MULTILINE)
for match in matches:
numbers_lijst.append(match.group(1))
return numbers_lijst
code = get_code(messages)
number = get_number(messages)
print(code)
print(number)
首先,永远不要遍历文件夹中的所有项目。使用 Items.Find/FindNext
或 Items.Restrict
并限制 ConversationTopic
(例如 [ConversationTopic] = 'Test1'
)。
要创建 date/time 限制,请添加范围限制 ([ReceivedTime] > 'some value') and [ReceivedTime] < 'other value'
我正在制作一个程序:
- 打开 outlook
- 按主题查找电子邮件
- 从电子邮件中提取一些日期(代码和编号)
- 将这些数据填入excel文件中。
标准电子邮件如下所示:
Subject: Test1
Hi,
You got a new answer from user Alex.
Code: alex123fj
Number1: 0611111111
Number2: 1020
Number3: 3032
我在这个过程中遇到了2个主要问题。
首先,我不知道如何在 outlook 中对电子邮件进行时间限制。例如,如果我只想阅读昨天的电子邮件。
其次,我保存在列表中的电子邮件中的所有代码和数字。但是每个项目都从这个 ["alex123fj"]
["alex123fj/r"]
我将不胜感激任何帮助或建议,这是我在 Python 中的第一个程序。
这是我的代码:
import win32com.client
import re
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.Folders('myemail@....').Folders('Inbox')
messages = inbox.Items
def get_code(messages):
codes_lijst = []
for message in messages:
subject = message.subject
if subject == "Test1":
body = message.body
matches = re.finditer("Code:\s(.*)$", body, re.MULTILINE)
for match in matches:
codes_lijst.append(match.group(1))
return codes_lijst
def get_number(messages):
numbers_lijst = []
for message in messages:
subject = message.subject
if subject == "Test1":
body = message.body
matches = re.finditer("Number:\s(.*)$", body, re.MULTILINE)
for match in matches:
numbers_lijst.append(match.group(1))
return numbers_lijst
code = get_code(messages)
number = get_number(messages)
print(code)
print(number)
首先,永远不要遍历文件夹中的所有项目。使用 Items.Find/FindNext
或 Items.Restrict
并限制 ConversationTopic
(例如 [ConversationTopic] = 'Test1'
)。
要创建 date/time 限制,请添加范围限制 ([ReceivedTime] > 'some value') and [ReceivedTime] < 'other value'