Search code examples
pythonoutlookwin32com

Choosing "From" field using python win32com outlook


I am trying to automate emails using python. Unfortunately, the network administrators at my work have blocked SMTP relay, so I cannot use that approach to send the emails (they are addressed externally).

I am therefore using win32com to automatically send these emails via outlook. This is working fine except for one thing. I want to choose the "FROM" field within my python code, but I simply cannot figure out how to do this.

Any insight would be greatly appreciated.


Solution

  • If you configured a separate POP3/SMTP account, set the MailItem.SendUsingAccount property to an account from the Namespace.Accounts collection.

    If you are sending on behalf of an Exchange user, set the MailItem.SentOnBehalfOfName property