问题
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