Send an AppointmentIthem with python win32com library

雨燕双飞 提交于 2020-01-03 04:16:11

问题


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()


来源:https://stackoverflow.com/questions/44437912/send-an-appointmentithem-with-python-win32com-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!