1

My overall goal is to send some generated emails via Outlook from Python/win32com (unfortunately this part isn't really feasible to change) and the method here works very well:

How do I generate and open an Outlook email with Python (but do not send)

I'm using it to generate the emails, with them showing up via the Outlook UI and then I either send them (possibly with editing) or cancel them (ie do not send).

However there is one limitation and from Googling and tinkering in Python I cannot see what I should do.

I would like to be able to programmatically log whether the displayed email was actually sent or cancelled.

I cannot see any value returned from mail.Display(True) and the mail object itself doesn't show any attributes that look like they indicate what happened.

Is there a way to do this?

Community
  • 1
  • 1
Neil
  • 686
  • 1
  • 9
  • 27

1 Answers1

0

MailItem object will fire the MailItem.Send event when it is sent.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • Thanks Dmitry. I'm not familiar with how that works - any more details you could add to the answer? – Neil Jan 10 '17 at 23:04
  • Okay. Should probably have been a comment rather than an answer then (but thanks all the same!) – Neil Jan 11 '17 at 09:51
  • It is an answer - the event will be raised. **How** you catch it in Python, is a different question. – Dmitry Streblechenko Jan 11 '17 at 13:37
  • I suspect we'll disagree here, but it sounds to me more like a statement that without further information doesn't actually fully answer the question at hand. – Neil Jan 11 '17 at 18:04
  • I can certainly help you with the Outlook questions, but I know next to nothing about Python. I answered your Outlook question. Now it is your turn to post a Python specific question like "How do I catch COM events in Python"? That would not be Outlook specific. – Dmitry Streblechenko Jan 11 '17 at 18:08
  • There are two parts to the question, you've answered one (notification of send), the other is notification of cancel. I believe the latter means detecting move to Deleted, not sure. Events are supposed to work in Python COM. – Oliver Jan 12 '17 at 06:13
  • There is no event when a message displayed by Outlook is dismissed because absolutely nothing happens in that case. It is not moved anywhere - if it was already saved, it stays in its parent folder. – Dmitry Streblechenko Jan 13 '17 at 13:23