-->

Send an AppointmentIthem with python win32com libr

2019-06-06 16:30发布

问题:

I'm developing a Python scripts to create a simple AppointmentItem and send it to some recipients using win32com library. I found all the documentation and some VBA examples in this link: https://msdn.microsoft.com‎ and everything seems to be clear and well exained. But, in my script, though the AppointmentItem is created and the Recipients resolved, I am not able to send it. The following is just an example of how looks the code.

outlook = win32com.client.Dispatch("Outlook.Application")
ns = outlook.GetNamespace("MAPI")
ns.Logon(profilename)

App = outlook.CreateItem(1)
App.Subject = "subject"
App.Body = "Meeting"
App.Location = "München"

App.Recipients.Add(recipient)
App.Recipients.ResolveAll()

App.Send()

Should I have necessarily an Exchange Account? Is there a workaround to avoid this problem? I can send normal email using this library using:

Msg = outlook.CreateItem(0)

instead of creating an appointment (fourth line). I tried, for this reason, to send an email with the appointment in attachment, but in the email there is no attachment.

回答1:

I found the solution and I'd like to post it, in order to help someone else, who may need it.

It's necessary just one code line more. The appointment should be changed into a meeting.

outlook = win32com.client.Dispatch("Outlook.Application")
ns = outlook.GetNamespace("MAPI")
ns.Logon(profilename)

App = outlook.CreateItem(1)
App.Subject = "subject"
App.Body = "Meeting"
App.Location = "München"

App.MeetingStatus = 1
App.Recipients.Add(recipient)
App.Recipients.ResolveAll()

App.Send()