-->

你如何设置邮件回复地址使用EWS托管API?(How do you set a message Re

2019-10-21 10:06发布

如何设置答复向发送使用PowerShell v3的使用Exchange Web服务托管API的消息时头?

我有一个Microsoft.Exchange.WebServices.Data.EmailMessage对象,可以从地址设置,添加附件,并成功地发送邮件。

我可以添加使用的X-header:

$xheader = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::InternetHeaders,"x-my-header",[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String)

并将其添加到$ pspropset但如果我使用答复为值的头没有被插入。

利用宝贵的,很难找到发表格伦信息秤这个线程我只相信两个扩展属性, PidTagReplyRecipientEntriesPidTagReplyRecipientNames需要在EmailMessage对象上设置。

我能够没有错误设置这两个扩展属性,但这不会导致一个应答消息中的报头。

下面相关的代码:

function SendResponse($orgMsg, $bodyTxt){
$message =  [Microsoft.Exchange.WebServices.Data.EmailMessage]::Bind($service, $($orgMsg.Id), $psPropset)
$reply = $message.CreateReply($true)
$reply.BodyPrefix = $bodyTxt
$replyMsg = $reply.Save($drftFolderid.Id)
$replyMsg.From = "my_desired_from@example.com"
$replyMsg.SetExtendedProperty($PidTagReplyRecipientEntries, $byteVal)
$replyMsg.SetExtendedProperty($PidTagReplyRecipientNames, "my_desired_replyto@example.com")
$replyMsg.Update([Microsoft.Exchange.WebServices.Data.ConflictResolutionMode]::AlwaysOverwrite)
$replyMsg.SendAndSaveCopy($sentFolderid.Id)
}

function convert-fromhex {
    process
    {
        $_ -replace '^0x', '' -split "(?<=\G\w{2})(?=\w{2})" | %{ [Convert]::ToByte( $_, 16 ) }
    }
}

# below is hex of string "my_desired_replyto@example.com"
[Byte[]]$byteVal = "6d795f646573697265645f7265706c79746f406578616d706c652e636f6d" | convert-fromhex

$PidTagReplyRecipientEntries = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x004F,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Binary)
$PidTagReplyRecipientNames = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x0050,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String)
$psPropset = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$psPropset.Add($PidTagReplyRecipientEntries)
$psPropset.Add($PidTagReplyRecipientNames)

有谁知道这是如何实现呢?

Answer 1:

不知道为什么你downvoted,但确实出现了一个EmailMessage.ReplyTo财产在Microsoft.Exchange.WebServices.Data.EmailMessage类。 我不知道它是只读的,但是。 看起来它可能是。



Answer 2:

据我知道你不能。 Replyto是只读属性。 我一直在尝试使用“ImpersonatedUserId”,但似乎有点麻烦(请参阅我无法得到它的工作)。 不过我也发现,如果你有模拟权限,那么你可以设置From属性,它会发送。 我理解这可能不是你要找的内容,但它会得到电子邮件来自于正确的地方。



文章来源: How do you set a message Reply-To address using EWS Managed API?