Sending an email through Python

和自甴很熟 提交于 2019-12-11 04:08:46

问题


I am trying to send an email through Python. I can get the email to display, but when I switch to send I get an error. This happens when I run this on a virtual machine. When I run on my laptop it works fine.

My Code:

#send email
import win32com.client
olMailItem = 0x0
obj = win32com.client.Dispatch("Outlook.Application")
newMail = obj.CreateItem(olMailItem)
newMail.Subject = "mysubject"
newMail.HTMLBody = "mybody"
newMail.To  = "myemail@gmail.com"
newMail.Send()

My error:

newMail.Send()
File "<COMObject CreateItem>", line 2, in Send
pywintypes.com_error: (-2147467260, 'Operation aborted', None, None)

I created a seperate file to get more info on the error:

import win32api
e_msg = win32api.FormatMessage(-2147457260)
print e_msg.decode('CP1251')

This yields the message:

pywintypes.error: (317, 'FormatMessage', 'The system cannot find message text for message number 0x%1 in message file for %2.')

What does this mean and what can be done to resolve it?

来源:https://stackoverflow.com/questions/26807942/sending-an-email-through-python

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