2

I am trying to send mail from another account (which is configured in my outlook but not default account) using the below code. The problem is when i keep mail.display(True) it is showing the account name but when i keep the mail.send instead of mail.display(True) the mail going from the default account.

from win32com.client import Dispatch
import win32com

outlook = win32com.client.Dispatch("Outlook.Application")
mail = outlook.CreateItem(0)
mail.SentOnBehalfOfName = 'xyz@gmail.com'
mail.To = 'mymail@gmail.com'
mail.Subject = 'Hello'
mail.HTMLBody = template
mail.send
Srinath Neela
  • 374
  • 1
  • 15
  • Have you tried the answer here: https://stackoverflow.com/questions/24454538/choosing-from-field-using-python-win32com-outlook ; it looks like SentOnBehalfOfName may only work with other exchange users, and SendUsingAccount should be used for other POP3/SMTP accounts. As an additional sanity check - does the user have the correct permissions to use sendAs? (https://learn.microsoft.com/en-us/graph/outlook-send-mail-from-other-user) – Peanut Butter Vibes Sep 23 '19 at 18:29

0 Answers0