2014-12-10 80 views
1

如何在使用PowerShell v3中的Exchange Web Services託管API發送消息時設置回覆標題?如何使用EWS託管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但如果我使用答覆爲值的頭沒有被插入。

使用寶貴的和難以找到Glen Scale在this thread發佈的信息我相信需要在EmailMessage對象上設置兩個擴展屬性PidTagReplyRecipientEntriesPidTagReplyRecipientNames

我能夠設置兩個擴展屬性沒有錯誤,但這不會導致郵件中的回覆標頭。

相關代碼如下:

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 = "[email protected]" 
$replyMsg.SetExtendedProperty($PidTagReplyRecipientEntries, $byteVal) 
$replyMsg.SetExtendedProperty($PidTagReplyRecipientNames, "[email protected]") 
$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 "[email protected]" 
[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) 

有誰知道這是如何實現呢?

+0

任何有關爲什麼這個問題被拒絕投票的見解也被讚賞。 – runaboutfence 2014-12-16 16:29:28

+0

我遇到同樣的問題,我希望回覆地址爲Exchange通訊組列表,所以我不能使用模擬,任何運氣? – Aaron 2016-03-14 13:22:44

回答

0

不知道爲什麼你被低估了,但Microsoft.Exchange.WebServices.Data.EmailMessage類似乎是an EmailMessage.ReplyTo property。但是,我不能說它是否是隻讀的。看起來可能是這樣。

+0

感謝您的回覆和投票! EmailMessage類中的EmailMessage.ReplyTo屬性是隻讀的。 我認爲當擴展屬性'PidTagReplyRecipientEntries'和'PidTagReplyRecipientNames'正確配置時,此屬性由Exchange傳輸提供程序設置。 – runaboutfence 2014-12-17 17:00:42

0

據我所知你不能。 Replyto是隻讀屬性。我一直試圖使用'ImpersonatedUserId',但它似乎有點笨重(讀我無法得到它的工作)。但是我確實發現,如果你有模擬權限,那麼你可以設置From屬性,它會發送。我知道這可能不是你想要的,但它會讓電子郵件來自正確的地方。

相關問題