I have been trying the below code.
def send_mail():
file_path = r""
outlook_app = win32.Dispatch('Outlook.Application')
olNS = outlook_app.GetNameSpace('MAPI')
# choose sender account
send_account = None
for account in outlook_app.Session.Accounts:
if account.DisplayName == '[email protected]':
# if account.SmtpAddress == "[email protected]":
send_account = account
break
mail_item = outlook_app.CreateItem(0) # 0: olMailItem
mail_item._oleobj_.Invoke(*(64209, 0, 8, 0, send_account))
#mail_item._oleobj_.Invoke(*(64209,0,8,0,olNS.Accounts.Item("[email protected]")))
mail_item.display()
mail_item.TO = '[email protected]'
# mail_item.CC = '[email protected]'
# mail_item.Recipients.Add('[email protected]')
mail_item.Subject = 'Test sending using particular account'
mail_item.BodyFormat = 1 # 1: Plain format
mail_item.Attachments.Add(file_path)
mail_item.Body = '''Hello, This is a test mail.\nThanks Guys.
'''
mail_item.Send()
Even after setting send_account, it is picking my organisation's mail id rather than the other one. I have used SendUsingAccount as well but getting the same result.