首页 文章

如何使用EWS托管API设置消息回复地址?

提问于
浏览
1

在Powershell v3中使用Exchange Web服务托管API发送邮件时,如何设置回复 Headers ?

我有一个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但如果我使用reply-to作为值,则不插入标头 .

使用有 Value 且很难找到Glen Scales在this thread中发布的信息我认为需要在EmailMessage对象上设置两个扩展属性 PidTagReplyRecipientEntriesPidTagReplyRecipientNames .

我可以设置两个扩展属性而不会出现错误,但这不会导致消息中的Reply-To标头 .

相关代码如下:

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)

有谁知道如何实现这一目标?

2 回答

  • 0

    不知道你为什么被downvoted,但在 Microsoft.Exchange.WebServices.Data.EmailMessage 类似乎确实有an EmailMessage.ReplyTo property . 不过,我可以't tell if it'只读 . 看起来可能是 .

  • 0

    据我所知你不能 . Replyto 是只读属性 . 我've been trying to use ' ImpersonatedUserId ' but it seems a little clunky (read I can' t让它工作) . 但是我确实发现如果你有模拟权限,那么你可以设置 From 属性,它将发送 . 我知道这可能不是你想要的,但它会让电子邮件来自正确的地方 .

相关问题