Sending Email with Python Win32Com.Client Send Error

断了今生、忘了曾经 提交于 2021-02-19 07:40:33

问题


I have my script to send out messages on Outlook via Python win32com.client. I can create the email and format my body but when I try to do newmail.Send()

I am getting an error I cannot figure out.

Below is my code along with the error:

obj = win32com.client.Dispatch("Outlook.Application")
newMail = obj.CreateItem(olMailItem)
newMail.Subject = "Subject"
newMail.Body = "Actualemail"
newMail.To = "test@test.com"
newMail.Send()

I get the follow error :

Traceback (most recent call last):
  File "<pyshell#105>", line 1, in <module>
    newMail.Send()
  File "<COMObject CreateItem>", line 2, in Send
pywintypes.com_error: (-2147467260, 'Operation aborted', None, None)

Anyone ever deal with this? Everything else works but the send function


回答1:


I found the issue. For some reason when I displayed the email and then sent it got it working.




回答2:


On

newMail = obj.CreateItem(olMailItem) 

Use the type value instead of the type name

Example

newMail = obj.CreateItem(0)


来源:https://stackoverflow.com/questions/59365331/sending-email-with-python-win32com-client-send-error

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