programmatically send outlook email from shared mailbox

偶尔善良 提交于 2019-12-01 04:50:24

问题


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?


回答1:


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.




回答2:


Added this right before the newMail.send() step and it worked

newMail.SentOnBehalfOfName = 'SharedFolder'


来源:https://stackoverflow.com/questions/38876817/programmatically-send-outlook-email-from-shared-mailbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!