使用 powershell -comobject outlook.application add CC 生成电子邮件

Generating an email with powershell -comobject outlook.application add CC

我找到了几个关于类似问题的主题,但我找不到这方面的任何文档,其中 none 直接对应我的问题。

$ol = New-Object -comObject Outlook.Application
$newmail = $ol.CreateItem(0) 
$newmail.Recipients.Add($Manager.EmailAddress)
$newmail.Recipients.Add($User.EmailAddress) 

我唯一需要做的就是在 CC 字段中创建第二个收件人 ($User.EmailAddress) 而不是 Outlook 草稿中的 "to" 字段。我怎样才能完成它?此外,是否有关于这些功能的文档?

干杯!

由于默认的收件人类型是olTo,您需要给第二个收件人一个不同的类型,即olCC:

$ol = New-Object -comObject Outlook.Application
$newmail = $ol.CreateItem(0) 
# the manager goes in the 'To'
$newmail.Recipients.Add($Manager.EmailAddress)

# this one should go in the 'CC'
$recip = $newmail.Recipients.Add($User.EmailAddress) 
$recip.Type = 2

对于 Outlook 收件人类型枚举,请看这里:https://msdn.microsoft.com/en-us/VBA/Outlook-VBA/articles/olmailrecipienttype-enumeration-outlook