pythonwindowsemailoutlookoutlook-2010

programmatically send outlook email from shared mailbox


I'm trying to send an email with python from a shared mailbox.

I have been able to sucessfuly send it through my own email, but sending one with a shared mailbox (that I have tested that I have access too) is giving me issues.

Code used for email script in python

import win32com.client
import win32com
olMailItem = 0x0
obj = win32com.client.Dispatch("Outlook.Application")
newMail = obj.CreateItem(olMailItem)
newMail.Subject = "Python Email Test"
newMail.Body = "Test"
newMail.To = 'hi@hi.com'
newMail.Send()

I know that below is how I can read my emails from a shared Folder. outlook = win32com.Dispatch("Outlook.Application").GetNamespace("MAPI") dir_accounts = outlook.Folders("SharedFolder")

Any ideas on how to combine these?


Solution

  • In case if you have multiple accounts configured in Outlook you may use the SendUsingAccount property of the MailItem class. Or if you have sufficient privileges (rights) you may consider using the SentOnBehalfOfName property which is a string indicating the display name for the intended sender of the mail message.