1

I want to send outlook email via python and I found below script

import win32com.client
from win32com.client import Dispatch, constants
const=win32com.client.constants
olMailItem = 0x0
obj = win32com.client.Dispatch("Outlook.Application")
newMail = obj.CreateItem(olMailItem)
newMail.Subject = "I AM SUBJECT!!"
newMail.BodyFormat = 2 
newMail.HTMLBody = "<HTML><BODY>Enter the <span style='color:red'>message</span> text here.</BODY></HTML>"
newMail.To = "[email protected]"
newMail.display()
newMail.Send()

Everything works fine untill newMail.Send(), it gives this error

Traceback (most recent call last):
  File "<ipython-input-46-7e8e370e48a8>", line 1, in <module>
    newMail.Send()
File "<COMObject CreateItem>", line 2, in Send
com_error: (-2147467260, 'Operation aborted', None, None)
3
  • Try the solutions mentioned at stackoverflow.com/questions/59365331/… or stackoverflow.com/questions/26807942/…. Neither has an accepted answer, but at least it'll give you something to try (which is a great thing to do before asking on SO). Commented Mar 30, 2020 at 14:14
  • Hey Manny, thanks for suggestions but still I could not find any solution that works for this problem Commented Mar 30, 2020 at 14:36
  • Add time.sleep(2) before send Commented Apr 4, 2020 at 5:19

1 Answer 1

1

You need to either display the message, or send it, but not both - your code displays the message, and then immediately sends it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.