Powershell:更改 Outlook com 对象中的发件人姓名

发布于 2025-01-13 22:32:04 字数 1078 浏览 1 评论 0原文

我想使用 Powershell 和 Outlook 发送电子邮件,但发件人电子邮件需要不同。 目前我拥有的是:

$OL = New-Object -comObject Outlook.Application
$mItem = $OL.CreateItem("olMailItem")

$mItem.SentOnBehalfOfName = "[email protected]"
$mItem.To = "[email protected]"
$mItem.Subject = "test"
$mItem.HTMLBody = "test"
$mItem.send()

我的 IT 管理员给了我一个额外的 Outlook 电子邮件地址。 因此,我添加了 SentOnBehalfOfName 行,但收到​​错误邮件:“无法发送此消息。您没有代表指定用户发送消息的权限。”

有人知道需要什么权限吗? 我有一个解决方案的想法,但我不知道它是否有效。我的 Outlook 有我的默认个人资料地址。 [email protected] 及其系统中某处的主要邮件,因此当我通过 powershell 制作 Outlook 电子邮件,它使用它。有没有办法切换到给我的新的?如果新的电子邮件是共享电子邮件,即使我是唯一的电子邮件,它仍然有效吗?

谢谢

编辑:请注意,通过更改“发件人”选项直接从 Outlook 执行此操作对我来说确实有效。所以现在我只需要通过 powershell 来完成。我也尝试设置 $mItem.Sender 但出现相同的错误。

I want to send out emails using Powershell and outlook but the sender email needs to be different.
Currently this is what i have:

$OL = New-Object -comObject Outlook.Application
$mItem = $OL.CreateItem("olMailItem")

$mItem.SentOnBehalfOfName = "[email protected]"
$mItem.To = "[email protected]"
$mItem.Subject = "test"
$mItem.HTMLBody = "test"
$mItem.send()

My IT admin gave me an additional outlook email address.
So i added the line for SentOnBehalfOfName but i get the error mail: "This message could not be sent. You do not have the permission to send the message on behalf of the specified user. "

Does anyone know what permissions are needed?
I had an idea for a solution but I don't if it would work. My outlook has my default profile address. [email protected] and its the primary one somewhere in the system so when i make an outlook email through powershell , it uses it. Is there a way to switch to the new one i was given? If the new one is a shared email even though i am the only one it, will it still work?

Thank you

EDIT: Note that doing it directly from outlook by changing the From option does work for me. So now i just need to do it by powershell. I also tried setting the $mItem.Sender but i get the same error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不…忘初心 2025-01-20 22:32:04

您无权代表他人发送。

在 Exchange Server 中,您可以使用 Exchange 管理中心 (EAC) 或 Exchange 命令行管理程序向邮箱或组分配权限,以便其他用户可以访问该邮箱(完全访问权限),或发送看似已发送的电子邮件。来自邮箱或组(代理发送或代表发送权限)。在其他邮箱或组上分配有这些权限的用户称为代理人。在管理收件人权限中了解更多相关信息文章。

使用 Powershell 授予代表发送权限页面显示可用于以编程方式设置权限的代码。

请注意,您可以考虑在 Outlook 中配置另一个帐户。在这种情况下,您不需要具有发送电子邮件的特殊权限。 MailItem.SendUsingAccount 属性允许设置一个 Account 对象,表示要发送 MailItem 的帐户。

You don't have permissions to send on behalf of another person.

In Exchange Server, you can use the Exchange admin center (EAC) or the Exchange Management Shell to assign permissions to a mailbox or group so that other users can access the mailbox (the Full Access permission), or send email messages that appear to come from the mailbox or group (the Send As or Send on Behalf permissions). The users that are assigned these permissions on other mailboxes or groups are called delegates. Read more about that in the Manage permissions for recipients article.

The Grant Send on Behalf Permissions using Powershell page shows the code which can be used to set up permissions programmatically.

Note, instead you may consider configuring another account in Outlook. In that case you don't need to have special permissions to send an email. The MailItem.SendUsingAccount property allows to set an Account object that represents the account under which the MailItem is to be sent.

﹏雨一样淡蓝的深情 2025-01-20 22:32:04

您需要拥有该用户的“发送为”权限。

You need to have the "send as" right for that user.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文