Skip to content Skip to sidebar Skip to footer

Need To Switch Accounts In Outlook Using Python For Sending Email Using Other Account

I have the following code import win32com.client as win32 outlook = win32.Dispatch('outlook.application') mail = outlook.CreateItem(0) mail.To = 'madanraj.c@sss.com; mail.Subject =

Solution 1:

Set MailItem.SendUsingAccount property.

Solution 2:

I know that this comes late but I think people might find it useful. This is how I've managed to select an e-mail address to send from, as I had multiple addresses in outlook.

import win32com.client as win32

outlook = win32.Dispatch('outlook.application') 

mail = outlook.CreateItem(0)
mail.Subject = "Test subject"
mail.To = "yourrecipient@gmail.com"# If you want to set which address the e-mail is sent from. # The e-mail needs to be part of your outlook account.From = None
for myEmailAddress in outlook.Session.Accounts:
    if"gmail.com" in str(myEmailAddress):
        From = myEmailAddress
        breakifFrom != None:
    # This line basically calls the "mail.SendUsingAccount = xyz@email.com" outlook VBA command
    mail._oleobj_.Invoke(*(64209, 0, 8, 0, From))

mail.Send()

Post a Comment for "Need To Switch Accounts In Outlook Using Python For Sending Email Using Other Account"