简体   繁体   English

以编程方式从共享邮箱发送 Outlook 电子邮件

[英]programmatically send outlook email from shared mailbox

I'm trying to send an email with python from a shared mailbox.我正在尝试从共享邮箱发送一封带有 python 的电子邮件。

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 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?关于如何结合这些的任何想法?

In case if you have multiple accounts configured in Outlook you may use the SendUsingAccount property of the MailItem class.如果您在 Outlook 中配置了多个帐户,您可以使用 MailItem 类的SendUsingAccount属性。 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.或者,如果您有足够的特权(权限),您可以考虑使用SentOnBehalfOfName属性,该属性是一个字符串,指示邮件消息的预期发件人的显示名称。

newMail.send()步骤之前添加了这个并且它起作用了

newMail.SentOnBehalfOfName = 'SharedFolder'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM