尝试通过Win32com客户端在Python中发送会议请求时出现错误消息

时间:2019-06-26 15:18:29

标签: python-3.x outlook pywin32 win32com

美好的一天,我正在尝试设置python脚本以通过Outlook发送会议邀请。在线快速搜索使我开始在Python上使用win32com.client模块,甚至遵循了快速食谱代码。如果这是一封简单的电子邮件,则该代码有效,但是将项目类型更改为会议邀请时出现错误。

我真的不知道从哪里开始进行故障排除。我曾尝试在Google上搜索类似的问题和错误代码,但到目前为止,我还没有发现与我类似的情况。我也不熟悉该异常产生的代码。

    import win32com.client
    outlook = win32com.client.Dispatch("Outlook.Application")


    def sendMeeting(apptTime, cell, recipients):
        appt = outlook.CreateItem(1) #appointment item
        appt.Start = apptTime # yyyy-MM-dd hh:mm
        appt.Subject = "5S Cross Audit"
        appt.Duration = 60 # minutes
        appt.Location = cell
        appt.MeetingStatus = 1 # 1 - changes the appointment to a meeting. Only after changing meetings status can recipients be added
        appt.Body = "This is a test email for the 5S Cross Audit invites"

        appt.Recipients.Add(recipients) # use ";" as delimiter

        appt.Save()
        appt.Send()

    meetingTime = "2019-06-27 10:00"
    auditCell = "CI Test"
    auditorHost = "email@host.com; email2@host.com"

    sendMeeting(meetingTime, auditCell, auditorHost)

运行此代码时,出现以下异常:

in appt.Send()
File "<COMObject CreateItem>", line 2, in Send
pywintypes.com_error 
(-2147352567, 'Exception occurred.', (4096, 'Microsoft Outlook', 'The operation failed.  The messaging interfaces have returned an unknown error. If the problem persists, restart Outlook. The operation failed. An object cannot be found.', None, 0, -2147221233), None)

0 个答案:

没有答案