Python Win32com Outlook 2013 Sendusingaccount Return Exception
While working on a simple mail automation with python and win32com api, I had an issue with SendUsingAccount. It was ignored or, worse, generating an error when I upgraded from win
Solution 1:
So, I found the solution to my problem by chance on this thread at the very bottom (most of it is for VBA but the last post solved the python issue).
Here is the working code
import win32com.client
o = win32com.client.Dispatch("Outlook.Application")
oacctouse = None
for oacc in o.Session.Accounts:
if oacc.SmtpAddress == "sender@mail.com":
oacctouse = oacc
break
Msg = o.CreateItem(0)
if oacctouse:
Msg._oleobj_.Invoke(*(64209, 0, 8, 0, oacctouse)) # Msg.SendUsingAccount = oacctouse
ifto:
Msg.To = ";".join(to)
if cc:
Msg.CC = ";".join(cc)
if bcc:
Msg.BCC = ";".join(bcc)
Msg.HTMLBody = ""
Msg.Send()
Post a Comment for "Python Win32com Outlook 2013 Sendusingaccount Return Exception"