Python win32com getting the size of email
Question: I'm trying to generate a certain amount of email traffic using Python 3 and
win32com with Outlook. I need to know the size of the emails that I'm creating
to make sure the correct amount of traffic is generated. I've been trying to
use the mailItem.Size property to get this information, but it is always
returning 0. The code I'm using is:

    
    
    from win32com.client import Dispatch
    outlook = Dispatch("Outlook.Application")
    message = outlook.createItem(0)
    
    message.To = "Test@mydomain.com"
    message.Subject = "Test"
    message.HtmlBody = "Test of win32com in Python"
    message.Attachments.Add(os.getcwd() + "\attachment.jpg")
    print(message.Size)
    message.Send
    

And all I get as output is 0. Regardless of whether I vary the body text or
remove the attachment. However, if I get the size of each component
individually, the Size property returns normally. But, the added up size isn't
the same as if I read from the Sent Items folder after waiting a few seconds.

Should I not be using the Size property of the mailItem?


Answer: You need to call MailItem.Save before reading the Size property.

