Python Outlook 按日期范围提取邮件给出了固定的下限,与用户输入无关

Python Outlook extract mails by Date Range gives a fixed lower limit, irrespective of User Input

这有点难以解释,但让我试试!!!

我尝试使用 Python (MAPI) 阅读 Outlook 邮件,每次我使用以下代码给出日期范围:

.Restrict("[ReceivedTime] >= '" + Start_user_input.strftime('%Y-%m-%d') + "' AND [ReceivedTime] <= '" + End_user_input.strftime('%Y-%m-%d') + "'"

例如范围是:从 20192020 的所有邮件。

但输出结果令人惊讶,从 25/06/2019 到任何用户上限。 无论如何,我给的下限,它总是会抛出来自 25/06/2019 的邮件。 今天它正在丢弃来自 26/06/2019.

的邮件

因此,可能是某些内部设置使其输出整整一年前的邮件。

Google 上没有关于这个确切问题的资源,因此 Whosebug 是最后的希望。

(此外,例如:从 2019/01/012019/06/26 的范围只给我 26 日的邮件。

我已经在其他 Outlook 帐户上试过了,但结果是一样的。)

要从满足预定义条件的文件夹中检索所有 Outlook 项目,您需要按升序对项目进行排序:

Imports System.Text
Imports System.Diagnostics
' ...
Private Sub RestrictCalendarItems(folder As Outlook.MAPIFolder)
    Dim dtEnd As DateTime = New DateTime(DateTime.Now.Year, DateTime.Now.Month, _
                                         DateTime.Now.Day, 23, 59, 0, 0)
    Dim restrictCriteria As String = "[Start]<=""" + dtEnd.ToString("g") + """" + _
                                     " AND [End]>=""" + DateTime.Now.ToString("g") + """"
    Dim strBuilder As StringBuilder = Nothing
    Dim folderItems As Outlook.Items = Nothing
    Dim resultItems As Outlook.Items = Nothing
    Dim appItem As Outlook._AppointmentItem = Nothing
    Dim counter As Integer = 0
    Dim item As Object = Nothing
   
        strBuilder = New StringBuilder()
        folderItems = folder.Items
        folderItems.IncludeRecurrences = True
        folderItems.Sort("[Start]")
        resultItems = folderItems.Restrict(restrictCriteria)
        item = resultItems.GetFirst()
        Do
            If Not IsNothing(item) Then
                If (TypeOf (item) Is Outlook._AppointmentItem) Then
                    counter = counter + 1
                    appItem = item
                    strBuilder.AppendLine("#" + counter.ToString() + _
                                          " Start: " + appItem.Start.ToString() + _
                                          " Subject: " + appItem.Subject + _
                                          " Location: " + appItem.Location)
                End If
                Marshal.ReleaseComObject(item)
                item = resultItems.GetNext()
            End If
        Loop Until IsNothing(item)
        If (strBuilder.Length > 0) Then
            Debug.WriteLine(strBuilder.ToString())
        Else
            Debug.WriteLine("There is no match in the " _
                             + folder.Name + " folder.")
        End If   
End Sub

在您的情况下,您需要调用 folderItems.Sort("[ReceivedTime]") 方法。