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 = '[email protected]'
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?
Outlook Desktop App (Windows)When composing a message click on the From in the drop-down box and select Other E-Mail Address. Type in the email address here that you wish to Send As and click OK. The next time you compose a message the Alternate Email Address will be available from the From Drop Down Box.
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.
Added this right before the newMail.send()
step and it worked
newMail.SentOnBehalfOfName = 'SharedFolder'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With