如何使用EWS托管API设置消息答复地址? [英] How do you set a message Reply-To address using EWS Managed API?

查看:94
本文介绍了如何使用EWS托管API设置消息答复地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do you set the reply-to header when sending a message using Exchange Web Services Managed API in Powershell v3?

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

I have a Microsoft.Exchange.WebServices.Data.EmailMessage object and can set the from address, add attachments, and send mail successfully.

我能够使用以下方式添加x标题:

I was able to add an x-header using:

$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作为值,则不会插入标头.

and adding it to $pspropset but if I use reply-to as the value the header is not inserted.

使用Glen Scales在

Using valuable and hard to find information posted by Glen Scales in this thread I believe two extended properties, PidTagReplyRecipientEntries and PidTagReplyRecipientNames need to be set on the EmailMessage object.

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

I am able to set both extended properties without errors but this does not result in a Reply-To header in the message.

以下相关代码:

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)

有人知道如何实现吗?

推荐答案

据我所知你做不到. Replyto是只读属性.我一直在尝试使用"ImpersonatedUserId",但似乎有些笨拙(请阅读我无法使其正常工作).但是我确实发现,如果您具有模拟权限,则可以设置From属性,它将发送.我了解这可能不是您要查找的内容,但是它将使电子邮件从正确的位置发出.

As far as I know you can't. Replyto is read-only property. I've been trying to use 'ImpersonatedUserId' but it seems a little clunky (read I can't getting it working). However I did find that if you have impersonation permissions then you can set Fromproperty and it will send. I understand this might not be what you're looking for but it will get the email to come from the right place.

这篇关于如何使用EWS托管API设置消息答复地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆